home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume25 / trash / part08 < prev    next >
Encoding:
Text File  |  1992-03-23  |  62.1 KB  |  3,025 lines

  1. Newsgroups: comp.sources.unix
  2. From: bruce@beta.cs.su.oz.au (Bruce Janson)
  3. Subject: v25i162: trash - simulate process execution in MIPS RISC/os 4.52, Part08/08
  4. Sender: unix-sources-moderator@pa.dec.com
  5. Approved: vixie@pa.dec.com
  6.  
  7. Submitted-By: bruce@beta.cs.su.oz.au (Bruce Janson)
  8. Posting-Number: Volume 25, Issue 162
  9. Archive-Name: trash/part08
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 8 (of 8)."
  18. # Contents:  sysv.c
  19. # Wrapped by bruce@basser on Tue Mar  3 23:25:24 1992
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'sysv.c' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'sysv.c'\"
  23. else
  24. echo shar: Extracting \"'sysv.c'\" \(58975 characters\)
  25. sed "s/^X//" >'sysv.c' <<'END_OF_FILE'
  26. X#include        <sys/param.h>
  27. X#include        <sys/types.h>
  28. X#include        <sys/statfs.h>
  29. X#include        <sys/stat.h>
  30. X#include        <sys/times.h>
  31. X#include        <sys/dirent.h>
  32. X#include        <sys/swap.h>
  33. X#include        <sys/utsname.h>
  34. X#include        <sys/termio.h>
  35. X#include        <sys/stermio.h>
  36. X#include        <sys/stropts.h>
  37. X#include        <sys/flio.h>
  38. X#include        <sys/mtio.h>
  39. X#include        <sys/fs/prfcntl.h>
  40. X#include        <sys/ptrace.h>
  41. X#include        <sys/immu.h>
  42. X#include        <sys/sbd.h>
  43. X#include        <sys/region.h>
  44. X#undef    PC
  45. X#if    defined(LIMITS)
  46. X#include        <sys/lnode.h>
  47. X#define    LIMITSoffset    (320 + SYSVoffset)
  48. X#endif    /* defined(LIMITS) */
  49. X#if    defined(SHARE)
  50. X#include        <sys/share.h>
  51. X#define    SHAREoffset    (323 + SYSVoffset)
  52. X#endif    /* defined(SHARE) */
  53. X#include        <sys/proc.h>
  54. X#include        <sys/fstyp.h>
  55. X#include        <sys/fsid.h>
  56. X#define    INKERNEL    1
  57. X#include        <signal.h>
  58. X#undef    INKERNEL
  59. X#include        <poll.h>
  60. X#include        <errno.h>
  61. X#include        <fcntl.h>
  62. X#include        <ustat.h>
  63. X#include        <sys.s>
  64. X#if    !defined(SYS_setlim)
  65. X#define    SYS_setlim    (0 + LIMITSoffset)
  66. X#define    SYS_getlim    (1 + LIMITSoffset)
  67. X#define    SYS_limonoff    (2 + LIMITSoffset)
  68. X#endif    /* !defined(SYS_setlim) */
  69. X#if    !defined(SYS_sharecosts)
  70. X#define    SYS_sharecosts    (0 + SHAREoffset)
  71. X#define    SYS_gettab    (1 + SHAREoffset)
  72. X#endif    /* !defined(SYS_sharecosts) */
  73. X#include        <stdio.h>
  74. X#include        <unistd.h>
  75. X#include        <bsd/sys/types.h>
  76. X#include        <bsd/sys/socket.h>
  77. X#include        <bsd/sys/uio.h>
  78. X#include        <bsd/sys/wait.h>
  79. X#include        <bsd/sys/time.h>
  80. X#include        <bsd/sys/resource.h>
  81. X#include        "register.h"
  82. X#include        "symtab.h"
  83. X#include        "diblock.h"
  84. X#include        "instrn.h"
  85. X#include        "process.h"
  86. X#include        "sysentry.h"
  87. X#include        "nels.h"
  88. X#include        "res.h"
  89. X#include        "flag.h"
  90. X#include        "generic.h"
  91. X
  92. Xextern time_t        time();
  93. X
  94. Xextern int        fd_lookup();
  95. Xextern int        fd_open();
  96. Xextern void        fd_dopen();
  97. Xextern int        fd_close();
  98. Xextern int        fd_invalid();
  99. Xextern int        fd_nfiles();
  100. Xextern int        fd_sort();
  101. Xextern void        histo_dump();
  102. Xextern void        hist_dump();
  103. Xextern char        *malloc();
  104. Xextern char        *strdup();
  105. Xextern int        bufset();
  106. Xextern int        mstrlen();
  107. Xextern int        mgetstring();
  108. Xextern int        mgets();
  109. Xextern char        **mgetvp();
  110. Xextern int        magic_ok();
  111. Xextern int        interpreter_ok();
  112. Xextern int        is_a_shared_library();
  113. Xextern int        augment_execve_args();
  114. Xextern void        vis_quoted_truncated_buffer();
  115. Xextern void        say_time();
  116. Xextern char        *signal_name();
  117. Xextern int        printval();
  118. Xextern int        bsd43_sys_ioctl();
  119. Xextern int        sgttybsize();
  120. X
  121. Xextern FILE        *outfp;
  122. Xextern int        errno;
  123. X
  124. Xextern int        Aflag;
  125. Xextern int        Fflag;
  126. Xextern int        Pflag;
  127. Xextern int        Sflag;
  128. X
  129. Xextern unsigned long    arg[];
  130. X
  131. Xextern int        return_errno;    /* errno goes here. */
  132. Xextern long        return_value0;    /* Result 1 value goes here. */
  133. Xextern long        return_value1;    /* Result 2 value goes here. */
  134. X
  135. Xextern sysentry        *current_sysentp;
  136. Xextern char        *sys_call_buf;    /* Scratch buf. */
  137. X
  138. Xstatic int        sysv_print_received_signal();
  139. X
  140. Xstatic
  141. Xint
  142. Xsys_execve(syscallno)
  143. Xint    syscallno;
  144. X{
  145. X    char    *filename;
  146. X    char    **argp;
  147. X    char    **envp;
  148. X    int    need_close_on_exec;
  149. X
  150. X    if (mgetstring(arg[0]) == -1)
  151. X        return -1;
  152. X
  153. X    if ((filename = strdup(sys_call_buf)) == (char *)0)
  154. X    {
  155. X        vcouldnot("execve(): ran out of memory");
  156. X        return -1;
  157. X    }
  158. X
  159. X    if ((argp = mgetvp(arg[1])) == (char **)0)
  160. X        return -1;
  161. X
  162. X    if ((envp = mgetvp(arg[2])) == (char **)0)
  163. X        return -1;
  164. X
  165. X    if (fd_sort() == -1)
  166. X        return -1;
  167. X
  168. X    if (Fflag)
  169. X    {
  170. X        int    mok;
  171. X
  172. X        if
  173. X        (
  174. X            access(filename, X_OK) != 0
  175. X            ||
  176. X            (mok = magic_ok(filename)) == 0
  177. X            ||
  178. X            (mok == 2 && interpreter_ok(filename) == 0)
  179. X            ||
  180. X            is_a_shared_library(filename)
  181. X        )
  182. X        {
  183. X            return_value0 = -1;
  184. X            return_errno = errno;
  185. X
  186. X            if (mfreevp(envp) == -1)
  187. X                return -1;
  188. X
  189. X            if (mfreevp(argp) == -1)
  190. X                return -1;
  191. X
  192. X            (void)free(filename);
  193. X
  194. X            return 0;
  195. X        }
  196. X
  197. X        if (augment_execve_args(&filename, &argp, &envp) == -1)
  198. X        {
  199. X            (void)mfreevp(envp);
  200. X            (void)mfreevp(argp);
  201. X            (void)free(filename);
  202. X        }
  203. X
  204. X        need_close_on_exec = 0;
  205. X    }
  206. X    else
  207. X    {
  208. X        histo_dump();
  209. X        hist_dump();
  210. X
  211. X        if (fcntl(fileno(outfp), F_SETFD, 1) == -1)
  212. X        {
  213. X            vcouldnot("fcntl(%d, F_SETFD, 1)", fileno(outfp));
  214. X            return -1;
  215. X        }
  216. X
  217. X        need_close_on_exec = 1;
  218. X    }
  219. X
  220. X    Rstart;
  221. X    return_value0 = syscall(syscallno, filename, argp, envp);
  222. X    return_errno = errno;
  223. X    Rstop;
  224. X
  225. X    if (need_close_on_exec)
  226. X    {
  227. X        if (fcntl(fileno(outfp), F_SETFD, 0) == -1)
  228. X        {
  229. X            vcouldnot("fcntl(%d, F_SETFD, 0)", fileno(outfp));
  230. X            return -1;
  231. X        }
  232. X    }
  233. X
  234. X    if (mfreevp(envp) == -1)
  235. X        return -1;
  236. X
  237. X    if (mfreevp(argp) == -1)
  238. X        return -1;
  239. X
  240. X    (void)free(filename);
  241. X
  242. X    return 0;
  243. X}
  244. X
  245. Xstatic
  246. Xint
  247. Xsys_fcntl(syscallno)
  248. Xint    syscallno;
  249. X{
  250. X    int    size;
  251. X    void    *fargp;
  252. X
  253. X    switch ((int)arg[1])
  254. X    {
  255. X    case F_DUPFD:
  256. X        Rstart;
  257. X        return_value0 = dup(fd_lookup((int)arg[0]));
  258. X        return_errno = errno;
  259. X        Rstop;
  260. X
  261. X        if (return_value0 != -1)
  262. X        {
  263. X            int    newfd;
  264. X            int    nfiles;
  265. X
  266. X            for (nfiles = fd_nfiles(), newfd = (int)arg[2]; newfd < nfiles && fd_lookup(newfd) != -1; newfd++)
  267. X                ;
  268. X
  269. X            if (newfd >= nfiles)
  270. X            {
  271. X                (void)close(return_value0);
  272. X                errno = EMFILE;
  273. X                return 0;
  274. X            }
  275. X
  276. X            fd_dopen(return_value0, newfd);
  277. X
  278. X            return_value0 = newfd;
  279. X        }
  280. X        return 0;
  281. X
  282. X    case F_GETFD:
  283. X    case F_SETFD:
  284. X    case F_GETFL:
  285. X    case F_SETFL:
  286. X    case F_SETOWN:
  287. X    case PFCSEXEC:
  288. X    case PFCREXEC:
  289. X    case PFCRUN:
  290. X    case PFCSSTEP:
  291. X    case PFCCSIG:
  292. X        size = -1;
  293. X        break;
  294. X
  295. X    case PFCWSTOP:
  296. X    case PFCGMASK:
  297. X    case PFCSMASK:
  298. X    case PFCSTOP:
  299. X        size = sizeof(unsigned long);
  300. X        break;
  301. X
  302. X    case PFCGETPR:
  303. X        size = sizeof(proc_t);
  304. X        break;
  305. X
  306. X    case PFCGETUSEG:
  307. X        size = sizeof(struct pfcseg);
  308. X        break;
  309. X
  310. X    case PFCGETREGS:
  311. X        size = sizeof(unsigned long) * NPTRC_REGS;
  312. X        break;
  313. X
  314. X    case F_SETLK:
  315. X    case F_SETLKW:
  316. X        size = sizeof(struct flock);
  317. X        break;
  318. X
  319. X    default:
  320. X        return -2;
  321. X    }
  322. X
  323. X    if (size != -1)
  324. X    {
  325. X        if (bufset(size) == -1)
  326. X            return -1;
  327. X
  328. X        if (mget(arg[2], sys_call_buf, size, &fargp) == -1)
  329. X            return -1;
  330. X    }
  331. X
  332. X    Rstart;
  333. X    return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), (int)arg[1], (size == -1) ? (int)arg[2] : (int)fargp);
  334. X    return_errno = errno;
  335. X    Rstop;
  336. X
  337. X    if (size != -1)
  338. X    {
  339. X        if (mput(arg[2], fargp, size, return_value0) == -1)
  340. X            return -1;
  341. X    }
  342. X
  343. X    return 0;
  344. X}
  345. X
  346. Xstatic
  347. Xint
  348. Xsys_fstat(syscallno)
  349. Xint    syscallno;
  350. X{
  351. X    return generic_fstat(syscallno, sizeof(struct stat));
  352. X}
  353. X
  354. Xstatic
  355. Xint
  356. Xsys_fstatfs(syscallno)
  357. Xint    syscallno;
  358. X{
  359. X    int        len;
  360. X    struct statfs    *bufp;
  361. X
  362. X    len = arg[2];
  363. X
  364. X    if (dmget(arg[1], len, &bufp) == -1)
  365. X        return -1;
  366. X
  367. X    Rstart;
  368. X    return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), bufp, len, (int)arg[3]);
  369. X    return_errno = errno;
  370. X    Rstop;
  371. X
  372. X    if (dmput(arg[1], bufp, len, return_value0) == -1)
  373. X        return -1;
  374. X
  375. X    return 0;
  376. X}
  377. X
  378. Xstatic
  379. Xint
  380. Xsys_getgid(syscallno)
  381. Xint    syscallno;
  382. X{
  383. X    Rstart;
  384. X    return_value0 = getgid();
  385. X    return_value1 = getegid();
  386. X    return_errno = errno;
  387. X    Rstop;
  388. X
  389. X    return 0;
  390. X}
  391. X
  392. Xstatic
  393. Xint
  394. Xsys_getgroups(syscallno)
  395. Xint    syscallno;
  396. X{
  397. X    return generic_getgroups(syscallno, NGROUPS);
  398. X}
  399. X
  400. Xstatic
  401. Xint
  402. Xsys_getitimer(syscallno)
  403. Xint    syscallno;
  404. X{
  405. X    return generic_getitimer(syscallno, sizeof(struct itimerval));
  406. X}
  407. X
  408. X#if    defined(LIMITS)
  409. Xstatic
  410. Xint
  411. Xsys_getlim(syscallno)
  412. Xint    syscallno;
  413. X{
  414. X    int    function;
  415. X    lnode    *address;
  416. X    int    size;
  417. X    int    realsize;
  418. X
  419. X    function = arg[0];
  420. X    size = arg[2];
  421. X
  422. X    switch (function)
  423. X    {
  424. X    case L_GETUID:
  425. X        realsize = sizeof(lnode);
  426. X        break;
  427. X
  428. X    default:
  429. X        realsize = size;
  430. X        break;
  431. X    }
  432. X
  433. X    if (dmget(arg[1], realsize, &address) == -1)
  434. X        return -1;
  435. X
  436. X    Rstart;
  437. X    return_value0 = syscall(syscallno, function, address, size);
  438. X    return_errno = errno;
  439. X    Rstop;
  440. X
  441. X    if (dmput(arg[1], address, realsize, return_value0) == -1)
  442. X        return -1;
  443. X
  444. X    return 0;
  445. X}
  446. X#endif    /* defined(LIMITS) */
  447. X
  448. Xstatic
  449. Xint
  450. Xsys_getrlimit(syscallno)
  451. Xint    syscallno;
  452. X{
  453. X    return generic_getrlimit(syscallno, sizeof(struct rlimit));
  454. X}
  455. X
  456. Xstatic
  457. Xint
  458. Xsys_getrusage(syscallno)
  459. Xint    syscallno;
  460. X{
  461. X    return generic_getrusage(syscallno, sizeof(struct rusage));
  462. X}
  463. X
  464. Xstatic
  465. Xint
  466. Xsys_gettimeofday(syscallno)
  467. Xint    syscallno;
  468. X{
  469. X    struct timeval    tv;
  470. X    struct timezone    tz;
  471. X
  472. X    return generic_gettimeofday(syscallno, &tv, sizeof(tv), &tz, sizeof(tz));
  473. X}
  474. X
  475. Xstatic
  476. Xint
  477. Xsys_getuid(syscallno)
  478. Xint    syscallno;
  479. X{
  480. X    Rstart;
  481. X    return_value0 = getuid();
  482. X    return_value1 = geteuid();
  483. X    return_errno = errno;
  484. X    Rstop;
  485. X
  486. X    return 0;
  487. X}
  488. X
  489. Xstatic
  490. Xint
  491. Xsys_ioctl(syscallno)
  492. Xint    syscallno;
  493. X{
  494. X    int    length;
  495. X    int    need_copy_in;
  496. X    int    need_copy_out;
  497. X    int    arg2_is_arg;
  498. X
  499. X    arg2_is_arg = 0;
  500. X
  501. X    if ((arg[1] & (unsigned long)(IOC_INOUT | IOC_VOID)) == 0)
  502. X    {
  503. X        /*
  504. X         * Old style.
  505. X         */
  506. X
  507. X        length = 0;
  508. X        need_copy_in = 0;
  509. X        need_copy_out = 0;
  510. X
  511. X        switch ((int)arg[1])
  512. X        {
  513. X        case FIONREAD:
  514. X            length = sizeof(int);
  515. X            need_copy_out = 1;
  516. X            break;
  517. X
  518. X        case FLIOC_SENSE_DRIVE:
  519. X            break;
  520. X
  521. X        case I_POP:
  522. X            break;
  523. X
  524. X        case I_PUSH:
  525. X            length = mstrlen(arg[2]) + 1;
  526. X            need_copy_in = 1;
  527. X            break;
  528. X
  529. X        case I_SRDOPT:
  530. X            length = sizeof(arg[2]);
  531. X            arg2_is_arg = 1;
  532. X            break;
  533. X
  534. X        case STGET:
  535. X            length = sizeof(struct stio);
  536. X            need_copy_out = 1;
  537. X            break;
  538. X
  539. X        case oTCGETA:
  540. X        case TCGETA:
  541. X            length = sizeof(struct termio);
  542. X            need_copy_out = 1;
  543. X            break;
  544. X
  545. X        case oTIOCGETP:
  546. X            length = sgttybsize();
  547. X            need_copy_out = 1;
  548. X            break;
  549. X
  550. X        case oTIOCSETP:
  551. X            length = sgttybsize();
  552. X            need_copy_in = 1;
  553. X            break;
  554. X
  555. X        case oTCSETA:
  556. X        case TCSETA:
  557. X        case oTCSETAF:
  558. X        case TCSETAF:
  559. X        case oTCSETAW:
  560. X        case TCSETAW:
  561. X            length = sizeof(struct termio);
  562. X            need_copy_in = 1;
  563. X            break;
  564. X
  565. X        case TCFLSH:
  566. X        case TCSBRK:
  567. X        case TCXONC:
  568. X            length = sizeof(arg[2]);
  569. X            arg2_is_arg = 1;
  570. X            break;
  571. X
  572. X        case oFIOCLEX:
  573. X        case oFIONCLEX:
  574. X            break;
  575. X
  576. X        case oTIOCEXCL:
  577. X        case TIOCEXCL:
  578. X            break;
  579. X
  580. X        case TIOCGPGRP:
  581. X            length = sizeof(int);
  582. X            need_copy_out = 1;
  583. X            break;
  584. X
  585. X        case TIOCGWINSZ:
  586. X            length = sizeof(struct winsize);
  587. X            need_copy_out = 1;
  588. X            break;
  589. X
  590. X        case MTIOCGET:
  591. X            /*
  592. X        case oTIOCHPCL:
  593. X             * Somebody has stuffed up here...
  594. X             * The MTIOCGET returns a struct,
  595. X             * the oTIOCHPCL doesn't but
  596. X             * they've got the same ioctl encoding.
  597. X             * So we try to guess based on the
  598. X             * pointer arg...
  599. X             */
  600. X            if (arg[2] != (unsigned long)0)
  601. X            {
  602. X                length = sizeof(struct mtget);
  603. X                need_copy_out = 1;
  604. X            }
  605. X            break;
  606. X
  607. X        case MTIOCTOP:
  608. X            length = sizeof(struct mtop);
  609. X            need_copy_in = 1;
  610. X            break;
  611. X
  612. X        case oTIOCNOTTY:
  613. X        case TIOCNOTTY:
  614. X            break;
  615. X
  616. X        case oTIOCNXCL:
  617. X        case TIOCNXCL:
  618. X            break;
  619. X
  620. X        case TIOCOUTQ:
  621. X            length = sizeof(int);
  622. X            need_copy_out = 1;
  623. X            break;
  624. X
  625. X        case TIOCSPGRP:
  626. X            length = sizeof(int);
  627. X            need_copy_in = 1;
  628. X            break;
  629. X
  630. X        case oTIOCSTI:
  631. X        case TIOCSTI:
  632. X            length = sizeof(char);
  633. X            need_copy_in = 1;
  634. X            break;
  635. X
  636. X        case TIOCSWINSZ:
  637. X            length = sizeof(struct winsize);
  638. X            need_copy_in = 1;
  639. X            break;
  640. X
  641. X        case LDSETT:
  642. X            length = sizeof(struct termcb);
  643. X            need_copy_in = 1;
  644. X            break;
  645. X
  646. X        default:
  647. X            return -2;
  648. X        }
  649. X    }
  650. X    else
  651. X    {
  652. X        /*
  653. X         * New style.
  654. X         */
  655. X
  656. X        need_copy_in = arg[1] & (unsigned long)IOC_IN;
  657. X        need_copy_out = arg[1] & (unsigned long)IOC_OUT;
  658. X        length = (arg[1] >> (unsigned long)16) & (unsigned long)IOCPARM_MASK;
  659. X    }
  660. X
  661. X    if (length > 0)
  662. X    {
  663. X        if (bufset((unsigned int)length) == -1)
  664. X            return -1;
  665. X
  666. X        if (need_copy_in)
  667. X        {
  668. X            if (quiet_procmget(GLOBALdipc, (unsigned long)arg[2], sys_call_buf, length) == -1)
  669. X                return -1;
  670. X        }
  671. X    }
  672. X
  673. X    /*
  674. X     * TODO: But what about fd's hidden in ioctl() args?
  675. X     *       strioctl() calls, for example.
  676. X     */
  677. X    Rstart;
  678. X    return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), (int)arg[1], arg2_is_arg ? (int)arg[2] : (int)sys_call_buf);
  679. X    return_errno = errno;
  680. X    Rstop;
  681. X
  682. X    if
  683. X    (
  684. X        need_copy_out
  685. X        &&
  686. X        return_value0 != -1
  687. X        &&
  688. X        quiet_procmput(GLOBALdipc, (unsigned long)arg[2], sys_call_buf, length) == -1
  689. X    )
  690. X        return -1;
  691. X
  692. X    return 0;
  693. X}
  694. X
  695. X/*
  696. X * Global entry point so that the bsd43 ioctl()
  697. X * can call the sysv ioctl() when it finds that
  698. X * it is really being called with sysv arguments
  699. X * .. yes, this is fairly gross.
  700. X */
  701. Xint
  702. Xsysv_sys_ioctl()
  703. X{
  704. X    static int    ive_been_called_before;
  705. X    int        result;
  706. X
  707. X    if (ive_been_called_before)
  708. X        result = -2;
  709. X    else
  710. X    {
  711. X        ive_been_called_before = 1;
  712. X        result = sys_ioctl(SYS_ioctl);
  713. X    }
  714. X
  715. X    ive_been_called_before = 0;
  716. X
  717. X    return result;
  718. X}
  719. X
  720. Xstatic
  721. Xint
  722. Xsys_lstat(syscallno)
  723. Xint    syscallno;
  724. X{
  725. X    struct stat    statb;
  726. X
  727. X    return generic_lstat(syscallno, &statb, sizeof(statb));
  728. X}
  729. X
  730. Xstatic
  731. Xint
  732. Xsys_ofcntl(syscallno)
  733. Xint    syscallno;
  734. X{
  735. X    switch ((int)arg[1])
  736. X    {
  737. X    case F_GETFL:
  738. X    case F_SETFL:
  739. X        Rstart;
  740. X        return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), (int)arg[1], (int)arg[2]);
  741. X        return_errno = errno;
  742. X        Rstop;
  743. X        break;
  744. X
  745. X    default:
  746. X        return sys_fcntl(SYS_fcntl);
  747. X    }
  748. X
  749. X    return 0;
  750. X}
  751. X
  752. Xstatic
  753. Xint
  754. Xsys_pipe(syscallno)
  755. Xint    syscallno;
  756. X{
  757. X    int    fds[2];
  758. X
  759. X    Rstart;
  760. X    return_value0 = pipe(&fds[0]);
  761. X    return_errno = errno;
  762. X    Rstop;
  763. X
  764. X    if (return_value0 != -1)
  765. X    {
  766. X        return_value0 = fd_open(fds[0]);
  767. X        return_value1 = fd_open(fds[1]);
  768. X    }
  769. X
  770. X    return 0;
  771. X}
  772. X
  773. Xstatic
  774. Xint
  775. Xsys_poll(syscallno)
  776. Xint    syscallno;
  777. X{
  778. X    unsigned long    nfds;
  779. X    int        timeout;
  780. X    int        size;
  781. X    struct pollfd    *fds;
  782. X    int        fd;
  783. X    int        *saved_fds;
  784. X
  785. X    nfds = arg[1];
  786. X    timeout = arg[2];
  787. X
  788. X    size = nfds * sizeof(fds[0]);
  789. X
  790. X    if (bufset(size) == -1)
  791. X        return -1;
  792. X
  793. X    if (mget(arg[0], sys_call_buf, size, &fds) == -1)
  794. X        return -1;
  795. X
  796. X    if (fds != (struct pollfd *)0)
  797. X    {
  798. X        if ((saved_fds = (int *)malloc(nfds * sizeof(int))) == (int *)0)
  799. X        {
  800. X            vcouldnot("allocate space for %d poll fds", nfds);
  801. X            return -1;
  802. X        }
  803. X
  804. X        for (fd = 0; fd < nfds; fd++)
  805. X        {
  806. X            saved_fds[fd] = fds[fd].fd;
  807. X            fds[fd].fd = fd_lookup(fds[fd].fd);
  808. X        }
  809. X    }
  810. X
  811. X    Rstart;
  812. X    return_value0 = syscall(syscallno, fds, nfds, timeout);
  813. X    return_errno = errno;
  814. X    Rstop;
  815. X
  816. X    if (fds != (struct pollfd *)0)
  817. X    {
  818. X        for (fd = 0; fd < nfds; fd++)
  819. X            fds[fd].fd = saved_fds[fd];
  820. X
  821. X        (void)free(saved_fds);
  822. X    }
  823. X
  824. X    if (mput(arg[0], fds, size, return_value0) == -1)
  825. X        return -1;
  826. X
  827. X    return 0;
  828. X}
  829. X
  830. Xstatic
  831. Xint
  832. Xsys_recvfrom(syscallno)
  833. Xint    syscallno;
  834. X{
  835. X    struct sockaddr    from;
  836. X
  837. X    return generic_recvfrom(syscallno, &from);
  838. X}
  839. X
  840. Xstatic
  841. Xint
  842. Xsys_recvmsg(syscallno)
  843. Xint    syscallno;
  844. X{
  845. X    struct msghdr    local_msghdr;
  846. X    struct msghdr    saved_local_msghdr;
  847. X    struct iovec    *saved_msg_iov;
  848. X
  849. X    if (quiet_procmget(GLOBALdipc, (unsigned long)arg[1], &local_msghdr, sizeof(local_msghdr)) == -1)
  850. X        return -1;
  851. X
  852. X    saved_local_msghdr = local_msghdr;
  853. X
  854. X    /*
  855. X     * Copy in the optional address.
  856. X     */
  857. X    if (local_msghdr.msg_name != (caddr_t)0)
  858. X    {
  859. X        caddr_t    name;
  860. X
  861. X        if ((name = (caddr_t)malloc(local_msghdr.msg_namelen)) == (caddr_t)0)
  862. X        {
  863. X            vcouldnot("allocate buffer for msg_name of length %d bytes", local_msghdr.msg_namelen);
  864. X            return -1;
  865. X        }
  866. X
  867. X        if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_name, name, (unsigned int)local_msghdr.msg_namelen) == -1)
  868. X            return -1;
  869. X
  870. X        local_msghdr.msg_name = name;
  871. X    }
  872. X
  873. X    /*
  874. X     * Copy in the scatter/gather array.
  875. X     */
  876. X    if (local_msghdr.msg_iov != (struct iovec *)0)
  877. X    {
  878. X        struct iovec    *v;
  879. X        int        i;
  880. X
  881. X        if ((v = (struct iovec *)malloc(local_msghdr.msg_iovlen * sizeof(*v))) == (struct iovec *)0)
  882. X        {
  883. X            vcouldnot("allocate buffer for scatter/gather vector of %d elements", local_msghdr.msg_iovlen);
  884. X            return -1;
  885. X        }
  886. X
  887. X        if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_iov, v, (unsigned int)local_msghdr.msg_iovlen * sizeof(*v)) == -1)
  888. X            return -1;
  889. X
  890. X        local_msghdr.msg_iov = v;
  891. X
  892. X        /*
  893. X         * Save a copy of the array.
  894. X         */
  895. X        if ((saved_msg_iov = (struct iovec *)malloc(local_msghdr.msg_iovlen * sizeof(*v))) == (struct iovec *)0)
  896. X        {
  897. X            vcouldnot("allocate buffer for saved scatter/gather vector of %d elements", local_msghdr.msg_iovlen);
  898. X            return -1;
  899. X        }
  900. X
  901. X        (void)memcpy(saved_msg_iov, v, local_msghdr.msg_iovlen * sizeof(*v));
  902. X
  903. X        /*
  904. X         * Copy in each entry of the array.
  905. X         */
  906. X        for (i = 0; i < local_msghdr.msg_iovlen; i++)
  907. X        {
  908. X            struct iovec    *liovp;
  909. X
  910. X            liovp = &(local_msghdr.msg_iov[i]);
  911. X
  912. X            if (liovp->iov_base != (caddr_t)0)
  913. X            {
  914. X                caddr_t    b;
  915. X
  916. X                if ((b = (caddr_t)malloc(liovp->iov_len)) == (caddr_t)0)
  917. X                {
  918. X                    vcouldnot("allocate buffer for member of scatter/gather vector of %d bytes", liovp->iov_len);
  919. X                    return -1;
  920. X                }
  921. X
  922. X                if (quiet_procmget(GLOBALdipc, (unsigned long)liovp->iov_base, b, (unsigned int)liovp->iov_len) == -1)
  923. X                    return -1;
  924. X
  925. X                liovp->iov_base = b;
  926. X            }
  927. X        }
  928. X    }
  929. X
  930. X    /*
  931. X     * Copy in the optional(?) access rights.
  932. X     */
  933. X    if (local_msghdr.msg_accrights != (caddr_t)0)
  934. X    {
  935. X        caddr_t    a;
  936. X
  937. X        if ((a = (caddr_t)malloc(local_msghdr.msg_accrightslen)) == (caddr_t)0)
  938. X        {
  939. X            vcouldnot("allocate buffer for access rights of length %d bytes", local_msghdr.msg_accrightslen);
  940. X            return -1;
  941. X        }
  942. X
  943. X        if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_accrights, a, (unsigned int)local_msghdr.msg_accrightslen) == -1)
  944. X            return -1;
  945. X
  946. X        local_msghdr.msg_accrights = a;
  947. X    }
  948. X
  949. X    Rstart;
  950. X    return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), &local_msghdr, (int)arg[2]);
  951. X    return_errno = errno;
  952. X    Rstop;
  953. X
  954. X    /*
  955. X     * Copy out fields to the user, free()'ing as we go.
  956. X     */
  957. X
  958. X    /*
  959. X     * Copy out the access rights.
  960. X     */
  961. X    if (saved_local_msghdr.msg_accrights != (caddr_t)0)
  962. X    {
  963. X        if (quiet_procmput(GLOBALdipc, (unsigned long)saved_local_msghdr.msg_accrights, local_msghdr.msg_accrights, (unsigned int)local_msghdr.msg_accrightslen) == -1)
  964. X            return -1;
  965. X
  966. X        (void)free((char *)local_msghdr.msg_accrights);
  967. X    }
  968. X
  969. X    /*
  970. X     * Copy out the scatter/gather array.
  971. X     */
  972. X    if (saved_local_msghdr.msg_iov != (struct iovec *)0)
  973. X    {
  974. X        int    i;
  975. X
  976. X        /*
  977. X         * Copy out each entry of the array.
  978. X         */
  979. X        for (i = 0; i < local_msghdr.msg_iovlen; i++)
  980. X        {
  981. X            struct iovec    *liovp;
  982. X
  983. X            liovp = &(local_msghdr.msg_iov[i]);
  984. X
  985. X            if (saved_msg_iov[i].iov_base != (caddr_t)0)
  986. X            {
  987. X                if (quiet_procmput(GLOBALdipc, (unsigned long)saved_msg_iov[i].iov_base, liovp->iov_base, (unsigned int)liovp->iov_len) == -1)
  988. X                    return -1;
  989. X                
  990. X                (void)free(liovp->iov_base);
  991. X            }
  992. X        }
  993. X
  994. X        (void)free(saved_msg_iov);
  995. X
  996. X        /*
  997. X         * Copy out the reconstructed array itself?
  998. X         */
  999. X
  1000. X        (void)free(local_msghdr.msg_iov);
  1001. X    }
  1002. X
  1003. X    /*
  1004. X     * Copy out the received name and its length?
  1005. X     */
  1006. X
  1007. X    (void)free(local_msghdr.msg_name);
  1008. X
  1009. X    return 0;
  1010. X}
  1011. X
  1012. X#define    select_dget(a,d,pp,m,nm)    \
  1013. X{ \
  1014. X    if (a == 0) \
  1015. X        pp = (struct fd_set *)0; \
  1016. X    else \
  1017. X    { \
  1018. X        struct fd_set    tfds; \
  1019. X        int        fd; \
  1020. X \
  1021. X        if (quiet_procmget(GLOBALdipc, (unsigned long)a, &tfds, howmany(m, NFDBITS) * sizeof(fd_mask)) == -1) \
  1022. X            return -1; \
  1023. X \
  1024. X        FD_ZERO(&d); \
  1025. X \
  1026. X        for (fd = 0; fd < m; fd++) \
  1027. X        { \
  1028. X            int    nfd; \
  1029. X \
  1030. X            if \
  1031. X            ( \
  1032. X                FD_ISSET(fd, &tfds) \
  1033. X                && \
  1034. X                (nfd = fd_lookup(fd)) != -1 \
  1035. X            ) \
  1036. X            { \
  1037. X                FD_SET(nfd, &d); \
  1038. X                if (nfd >= nm) \
  1039. X                    nm = nfd + 1; \
  1040. X            } \
  1041. X        } \
  1042. X \
  1043. X        pp = &d; \
  1044. X    } \
  1045. X}
  1046. X
  1047. X#define    select_tget(a,d,p,t)    \
  1048. X{ \
  1049. X    if (a == 0) \
  1050. X        p = (t *)0; \
  1051. X    else \
  1052. X    { \
  1053. X        if (quiet_procmget(GLOBALdipc, (unsigned long)a, &d, sizeof(d)) == -1) \
  1054. X            return -1; \
  1055. X \
  1056. X        p = &d; \
  1057. X    } \
  1058. X}
  1059. X
  1060. X#define    select_dput(a,pp,nn)    \
  1061. X{ \
  1062. X    if (a != 0) \
  1063. X    { \
  1064. X        struct fd_set    tfds; \
  1065. X        int        fd; \
  1066. X \
  1067. X        FD_ZERO(&tfds); \
  1068. X \
  1069. X        for (fd = 0; fd < nn; fd++) \
  1070. X        { \
  1071. X            int    nfd; \
  1072. X \
  1073. X            if \
  1074. X            ( \
  1075. X                (nfd = fd_lookup(fd)) != -1 \
  1076. X                && \
  1077. X                FD_ISSET(nfd, pp) \
  1078. X            ) \
  1079. X                FD_SET(fd, &tfds); \
  1080. X        } \
  1081. X \
  1082. X        if (quiet_procmput(GLOBALdipc, (unsigned long)a, &tfds, howmany(nn, NFDBITS) * sizeof(fd_mask)) == -1) \
  1083. X            return -1; \
  1084. X    } \
  1085. X}
  1086. X
  1087. Xstatic
  1088. Xint
  1089. Xsys_select(syscallno)
  1090. Xint    syscallno;
  1091. X{
  1092. X    struct fd_set    rfds;
  1093. X    struct fd_set    *rfdsp;
  1094. X    struct fd_set    wfds;
  1095. X    struct fd_set    *wfdsp;
  1096. X    struct fd_set    efds;
  1097. X    struct fd_set    *efdsp;
  1098. X    struct timeval    timeout;
  1099. X    struct timeval    *timeoutp;
  1100. X    int        nfds;
  1101. X    int        newnfds;
  1102. X
  1103. X    nfds = (int)arg[0];
  1104. X    if (nfds > fd_nfiles())
  1105. X        nfds = fd_nfiles();
  1106. X    newnfds = 0;
  1107. X
  1108. X    select_dget(arg[1], rfds, rfdsp, nfds, newnfds);
  1109. X    select_dget(arg[2], wfds, wfdsp, nfds, newnfds);
  1110. X    select_dget(arg[3], efds, efdsp, nfds, newnfds);
  1111. X    select_tget(arg[4], timeout, timeoutp, struct timeval);
  1112. X
  1113. X    Rstart;
  1114. X    return_value0 = syscall(syscallno, newnfds, rfdsp, wfdsp, efdsp, timeoutp);
  1115. X    return_errno = errno;
  1116. X    Rstop;
  1117. X
  1118. X    if (return_value0 != -1)
  1119. X    {
  1120. X        select_dput(arg[3], efdsp, nfds);
  1121. X        select_dput(arg[2], wfdsp, nfds);
  1122. X        select_dput(arg[1], rfdsp, nfds);
  1123. X    }
  1124. X
  1125. X    return 0;
  1126. X}
  1127. X
  1128. Xstatic
  1129. Xint
  1130. Xsys_sendmsg(syscallno)
  1131. Xint    syscallno;
  1132. X{
  1133. X    struct msghdr    local_msghdr;
  1134. X
  1135. X    if (quiet_procmget(GLOBALdipc, (unsigned long)arg[1], &local_msghdr, sizeof(local_msghdr)) == -1)
  1136. X        return -1;
  1137. X
  1138. X#if    0
  1139. Xfprintf(outfp, "local_msghdr.msg_name = 0x%x\n", local_msghdr.msg_name);
  1140. Xfprintf(outfp, "local_msghdr.msg_namelen = %d\n", local_msghdr.msg_namelen);
  1141. X#endif    /* 0 */
  1142. X
  1143. X    /*
  1144. X     * Copy in the optional address.
  1145. X     */
  1146. X    if (local_msghdr.msg_name != (caddr_t)0)
  1147. X    {
  1148. X        caddr_t    name;
  1149. X
  1150. X        if ((name = (caddr_t)malloc(local_msghdr.msg_namelen)) == (caddr_t)0)
  1151. X        {
  1152. X            vcouldnot("allocate buffer for msg_name of length %d bytes", local_msghdr.msg_namelen);
  1153. X            return -1;
  1154. X        }
  1155. X
  1156. X        if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_name, name, (unsigned int)local_msghdr.msg_namelen) == -1)
  1157. X            return -1;
  1158. X
  1159. X        local_msghdr.msg_name = name;
  1160. X
  1161. X#if    0
  1162. X{
  1163. X    int    i;
  1164. X
  1165. X    fprintf(outfp, "msg_name =");
  1166. X    for (i = 0; i < local_msghdr.msg_namelen; i++)
  1167. X        fprintf(outfp, "%02x", local_msghdr.msg_name[i] & 0xFF);
  1168. X    fprintf(outfp, "\n");
  1169. X}
  1170. X#endif    /* 0 */
  1171. X    }
  1172. X
  1173. X#if    0
  1174. Xfprintf(outfp, "local_msghdr.msg_iov = 0x%x\n", local_msghdr.msg_iov);
  1175. Xfprintf(outfp, "local_msghdr.msg_iovlen = %d\n", local_msghdr.msg_iovlen);
  1176. X#endif    /* 0 */
  1177. X
  1178. X    /*
  1179. X     * Copy in the scatter/gather array.
  1180. X     */
  1181. X    if (local_msghdr.msg_iov != (struct iovec *)0)
  1182. X    {
  1183. X        struct iovec    *v;
  1184. X        int        i;
  1185. X
  1186. X        if ((v = (struct iovec *)malloc(local_msghdr.msg_iovlen * sizeof(*v))) == (struct iovec *)0)
  1187. X        {
  1188. X            vcouldnot("allocate buffer for scatter/gather vector of %d elements", local_msghdr.msg_iovlen);
  1189. X            return -1;
  1190. X        }
  1191. X
  1192. X        if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_iov, v, (unsigned int)local_msghdr.msg_iovlen * sizeof(*v)) == -1)
  1193. X            return -1;
  1194. X
  1195. X        local_msghdr.msg_iov = v;
  1196. X
  1197. X        /*
  1198. X         * Copy in each entry in the array.
  1199. X         */
  1200. X        for (i = 0; i < local_msghdr.msg_iovlen; i++)
  1201. X        {
  1202. X            struct iovec    *liovp;
  1203. X
  1204. X            liovp = &(local_msghdr.msg_iov[i]);
  1205. X
  1206. X#if    0
  1207. Xfprintf(outfp, "local_msghdr.msg_iov[%d].iov_base = 0x%x\n", i, liovp->iov_base);
  1208. Xfprintf(outfp, "local_msghdr.msg_iov[%d].iov_len = %d\n", i, liovp->iov_len);
  1209. X#endif    /* 0 */
  1210. X
  1211. X            if (liovp->iov_base != (caddr_t)0)
  1212. X            {
  1213. X                caddr_t    b;
  1214. X
  1215. X                if ((b = (caddr_t)malloc(liovp->iov_len)) == (caddr_t)0)
  1216. X                {
  1217. X                    vcouldnot("allocate buffer for member of scatter/gather vector of %d bytes", liovp->iov_len);
  1218. X                    return -1;
  1219. X                }
  1220. X
  1221. X                if (quiet_procmget(GLOBALdipc, (unsigned long)liovp->iov_base, b, (unsigned int)liovp->iov_len) == -1)
  1222. X                    return -1;
  1223. X
  1224. X                liovp->iov_base = b;
  1225. X            }
  1226. X        }
  1227. X    }
  1228. X
  1229. X#if    0
  1230. Xfprintf(outfp, "local_msghdr.msg_accrights = %d\n", local_msghdr.msg_accrights);
  1231. Xfprintf(outfp, "local_msghdr.msg_accrightslen = %d\n", local_msghdr.msg_accrightslen);
  1232. X#endif    /* 0 */
  1233. X
  1234. X    /*
  1235. X     * Copy in the optional(?) access rights.
  1236. X     */
  1237. X    if (local_msghdr.msg_accrights != (caddr_t)0)
  1238. X    {
  1239. X        caddr_t    a;
  1240. X
  1241. X        if ((a = (caddr_t)malloc(local_msghdr.msg_accrightslen)) == (caddr_t)0)
  1242. X        {
  1243. X            vcouldnot("allocate buffer for access rights of length %d bytes", local_msghdr.msg_accrightslen);
  1244. X            return -1;
  1245. X        }
  1246. X
  1247. X        if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_accrights, a, (unsigned int)local_msghdr.msg_accrightslen) == -1)
  1248. X            return -1;
  1249. X
  1250. X        local_msghdr.msg_accrights = a;
  1251. X    }
  1252. X
  1253. X    Rstart;
  1254. X    return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), &local_msghdr, (int)arg[2]);
  1255. X    return_errno = errno;
  1256. X    Rstop;
  1257. X
  1258. X    /*
  1259. X     * Should we copy out any of these fields to the user?
  1260. X     * Assuming "no" until demonstrated otherwise.
  1261. X     */
  1262. X    
  1263. X    /*
  1264. X     * Free up all the temporary space...
  1265. X     */
  1266. X
  1267. X    if (local_msghdr.msg_accrights != (caddr_t)0)
  1268. X        (void)free((char *)local_msghdr.msg_accrights);
  1269. X
  1270. X    if (local_msghdr.msg_iov != (struct iovec *)0)
  1271. X    {
  1272. X        int    i;
  1273. X
  1274. X        for (i = 0; i < local_msghdr.msg_iovlen; i++)
  1275. X        {
  1276. X            struct iovec    *liovp;
  1277. X
  1278. X            liovp = &local_msghdr.msg_iov[i];
  1279. X
  1280. X            if (liovp->iov_base != (caddr_t)0)
  1281. X                (void)free((char *)liovp->iov_base);
  1282. X        }
  1283. X
  1284. X        (void)free((char *)local_msghdr.msg_iov);
  1285. X    }
  1286. X
  1287. X    if (local_msghdr.msg_name != (caddr_t)0)
  1288. X        (void)free((char *)local_msghdr.msg_name);
  1289. X
  1290. X    return 0;
  1291. X}
  1292. X
  1293. Xstatic
  1294. Xint
  1295. Xsys_sendto(syscallno)
  1296. Xint    syscallno;
  1297. X{
  1298. X    struct sockaddr    to;
  1299. X
  1300. X    return generic_sendto(syscallno, &to);
  1301. X}
  1302. X
  1303. Xstatic
  1304. Xint
  1305. Xsys_setitimer(syscallno)
  1306. Xint    syscallno;
  1307. X{
  1308. X    struct itimerval    it;
  1309. X    struct itimerval    oit;
  1310. X
  1311. X    return generic_setitimer(syscallno, &it, sizeof(it), &oit, sizeof(oit));
  1312. X}
  1313. X
  1314. Xstatic
  1315. Xint
  1316. Xsys_setpgrp(syscallno)
  1317. Xint    syscallno;
  1318. X{
  1319. X    Rstart;
  1320. X    return_value0 = syscall(syscallno, arg[0]);
  1321. X    return_errno = errno;
  1322. X    Rstop;
  1323. X
  1324. X    return 0;
  1325. X}
  1326. X
  1327. Xstatic
  1328. Xint
  1329. Xsys_setrlimit(syscallno)
  1330. Xint    syscallno;
  1331. X{
  1332. X    return generic_setrlimit(syscallno, sizeof(struct rlimit));
  1333. X}
  1334. X
  1335. X#if    defined(SHARE)
  1336. Xstatic
  1337. Xint
  1338. Xsys_sharecosts(syscallno)
  1339. Xint    syscallno;
  1340. X{
  1341. X    int            function;
  1342. X    struct sh_consts    *address;
  1343. X    int            size;
  1344. X
  1345. X    function = arg[0];
  1346. X    size = arg[2];
  1347. X
  1348. X    if (dmget(arg[1], size, &address) == -1)
  1349. X        return -1;
  1350. X
  1351. X    Rstart;
  1352. X    return_value0 = syscall(syscallno, function, address, size);
  1353. X    return_errno = errno;
  1354. X    Rstop;
  1355. X
  1356. X    if (dmput(arg[1], address, size, return_value0) == -1)
  1357. X        return -1;
  1358. X
  1359. X    return 0;
  1360. X}
  1361. X#endif    /* defined(SHARE) */
  1362. X
  1363. X#if    0
  1364. X#define    SIG_DEBUG    1
  1365. X#endif    /* 0 */
  1366. X
  1367. X#define    SH_DFL        0
  1368. X#define    SH_HOLD        1
  1369. X
  1370. Xtypedef struct siginfo    siginfo;
  1371. Xstruct siginfo
  1372. X{
  1373. X    unsigned long        sig_handler;
  1374. X    int            sig_handler_type;
  1375. X    unsigned long        sig_tramp;
  1376. X    int            sig_code;
  1377. X    struct sigcontext    sig_context;
  1378. X    int            sig_pending;
  1379. X};
  1380. X
  1381. Xstatic siginfo        sinfo[NSIG];
  1382. X
  1383. Xint            sigs_pending;
  1384. X
  1385. Xstatic
  1386. Xvoid
  1387. Xour_handler(sig, code, scp)
  1388. Xint            sig;
  1389. Xint            code;
  1390. Xstruct sigcontext    *scp;
  1391. X{
  1392. X    sinfo[sig].sig_pending++;
  1393. X    sigs_pending++;
  1394. X
  1395. X    sinfo[sig].sig_code = code;
  1396. X    sinfo[sig].sig_context = *scp;
  1397. X
  1398. X#if    defined(SIG_DEBUG)
  1399. X    if (sysv_print_received_signal(U_SYSV, "sysv_debug", sinfo[sig].sig_tramp, sinfo[sig].sig_handler, sig, sinfo[sig].sig_code, scp) == -1)
  1400. X        return -1;
  1401. X#endif    /* defined(SIG_DEBUG) */
  1402. X
  1403. X    /*
  1404. X     * All of our handlers are of the "sigset()" kind.
  1405. X     * Normally this would mean that:
  1406. X     *    1. during the execution of the handler, any
  1407. X     *       further arrivals of the same signal are held.
  1408. X     *    2. on return from the handler, the same handler
  1409. X     *       is restored and any held signal is delivered.
  1410. X     * We want to keep the first property but we want to
  1411. X     * modify the second property so that, instead of
  1412. X     * restoring the signal handler and re-enabling signals
  1413. X     * immediately, we continue to hold signals
  1414. X     * and only release them and restore the handler at
  1415. X     * a later time (i.e. when we actually simulate signal delivery).
  1416. X     * This assignment to "scp->is_sigset" accomplishes this.
  1417. X     */
  1418. X    scp->is_sigset = 0;
  1419. X}
  1420. X
  1421. Xdinstrn    *
  1422. Xdeliver_signal(dipc)
  1423. Xdinstrn    *dipc;
  1424. X{
  1425. X    int            i;
  1426. X    struct sigcontext    *sscp;
  1427. X    int            regmask;
  1428. X    int            regbit;
  1429. X    int            regi;
  1430. X
  1431. X    for (i = 0; i < nels(sinfo); i++)
  1432. X    {
  1433. X        if (sinfo[i].sig_pending > 0)
  1434. X        {
  1435. X            /*
  1436. X             * Massage saved sigcontext.
  1437. X             */
  1438. X            sinfo[i].sig_context.sc_pc = dipc->di_addr;
  1439. X
  1440. X            regmask = 0xFFFFFFFF;    
  1441. X            sinfo[i].sig_context.sc_regmask = regmask;    
  1442. X
  1443. X            sinfo[i].sig_context.sc_regs[0] = 0;
  1444. X            for
  1445. X            (
  1446. X                regi = 1, regbit = 1 << 1;
  1447. X                regi < nels(sinfo[i].sig_context.sc_regs);
  1448. X                regi++, regbit <<= 1
  1449. X            )
  1450. X            {
  1451. X                if (regmask & regbit)
  1452. X                {
  1453. X                    int    saved_give_warnings;
  1454. X
  1455. X                    if (PG(regi) == R_K0 || PG(regi) == R_K1)
  1456. X                    {
  1457. X                        saved_give_warnings = give_warnings;
  1458. X                        give_warnings = 0;
  1459. X                    }
  1460. X
  1461. X                    if (quiet_procsget(PG(regi), &sinfo[i].sig_context.sc_regs[regi]) == -1)
  1462. X                        return dipc;
  1463. X
  1464. X                    if (PG(regi) == R_K0 || PG(regi) == R_K1)
  1465. X                        give_warnings = saved_give_warnings;
  1466. X                }
  1467. X            }
  1468. X
  1469. X            if (quiet_procsget(R_HI, &sinfo[i].sig_context.sc_mdhi) == -1)
  1470. X                return dipc;
  1471. X
  1472. X            if (quiet_procsget(R_LO, &sinfo[i].sig_context.sc_mdlo) == -1)
  1473. X                return dipc;
  1474. X#if    0
  1475. X            /*
  1476. X             * TODO: floating point? exceptions?
  1477. X             */
  1478. X            {
  1479. X                int *srp, *frp;
  1480. X                uint *urp;
  1481. X
  1482. X                scp->sc_ownedfp = u.u_pcb.pcb_ownedfp;
  1483. X
  1484. X                if ((regmask & 1) && u.u_pcb.pcb_ownedfp)
  1485. X                {
  1486. X                    checkfp (u.u_procp, 0);    /* dump fp to pcb */
  1487. X                    for
  1488. X                    (
  1489. X                        srp = &scp->sc_fpregs[0], frp = u.u_pcb.pcb_fpregs;
  1490. X                        frp < &u.u_pcb.pcb_fpregs[32];
  1491. X                        srp++, frp++
  1492. X                    )
  1493. X                        *srp = *frp;
  1494. X                    scp->sc_fpc_csr = u.u_pcb.pcb_fpc_csr;
  1495. X                    scp->sc_fpc_eir = u.u_pcb.pcb_fpc_eir;
  1496. X                    u.u_pcb.pcb_fpc_csr &= ~FPCSR_EXCEPTIONS;
  1497. X                }
  1498. X
  1499. X                scp->sc_cause = USER_REG(EF_CAUSE);
  1500. X                scp->sc_badvaddr = USER_REG(EF_BADVADDR);
  1501. X            }
  1502. X#endif    /* 0 */
  1503. X
  1504. X            /*
  1505. X             * Store massaged sigcontext on stack.
  1506. X             */
  1507. X            if (quiet_procsget(R_SP, &sscp) == -1)
  1508. X                return dipc;
  1509. X
  1510. X            /*
  1511. X             * Make room.
  1512. X             */
  1513. X            sscp--;
  1514. X
  1515. X            /*
  1516. X             * Ensure quad word aligned.
  1517. X             */
  1518. X            sscp = (struct sigcontext *)(((unsigned long)sscp) & ~0xF);
  1519. X
  1520. X            if (quiet_procmput(GLOBALdipc, (unsigned long)sscp, &sinfo[i].sig_context, sizeof(sinfo[i].sig_context)) == -1)
  1521. X                return dipc;
  1522. X
  1523. X            if (Pflag || Sflag)
  1524. X            {
  1525. X                if (sysv_print_received_signal(U_SYSV, "sysv", sinfo[i].sig_tramp, sinfo[i].sig_handler, i, sinfo[i].sig_code, sscp) == -1)
  1526. X                    return dipc;
  1527. X            }
  1528. X
  1529. X            /*
  1530. X             * Set up arguments and SP for sig_tramp() call.
  1531. X             */
  1532. X            if (quiet_procsput(R_A0, i) == -1)
  1533. X                return dipc;
  1534. X
  1535. X            if (quiet_procsput(R_A1, sinfo[i].sig_code) == -1)
  1536. X                return dipc;
  1537. X
  1538. X            if (quiet_procsput(R_A2, sscp) == -1)
  1539. X                return dipc;
  1540. X
  1541. X            if (quiet_procsput(R_SP, sscp) == -1)
  1542. X                return dipc;
  1543. X
  1544. X            if (quiet_procsput(R_A3, sinfo[i].sig_handler) == -1)
  1545. X                return dipc;
  1546. X
  1547. X            /*
  1548. X             * Set up PC for sig_tramp() call.
  1549. X             */
  1550. X            if ((dipc = addr_to_decoded_instrnp(dipc, sinfo[i].sig_tramp)) == (dinstrn *)0)
  1551. X                return dipc;
  1552. X
  1553. X            dipc--;
  1554. X
  1555. X            sigs_pending--;
  1556. X            sinfo[i].sig_pending--;
  1557. X
  1558. X            if (sinfo[i].sig_handler_type == SH_DFL)
  1559. X                (void)sigset(i, SIG_DFL);
  1560. X
  1561. X            break;
  1562. X        }
  1563. X    }
  1564. X
  1565. X    return dipc;
  1566. X}
  1567. X
  1568. Xstatic
  1569. Xint
  1570. Xsys_signal(syscallno)
  1571. Xint    syscallno;
  1572. X{
  1573. X    int    signo;
  1574. X    int    sigbits;
  1575. X
  1576. X    signo = arg[0] & SIGNO_MASK;
  1577. X    sigbits = arg[0] & ~SIGNO_MASK;
  1578. X
  1579. X    switch ((int)arg[1])
  1580. X    {
  1581. X    case SIG_IGN:
  1582. X    case SIG_DFL:
  1583. X    case SIG_HOLD:
  1584. X        return_value0 = (long)sigset(signo, arg[1]);
  1585. X        if
  1586. X        (
  1587. X            return_value0 != (long)SIG_ERR
  1588. X            &&
  1589. X            return_value0 != (long)SIG_DFL
  1590. X            &&
  1591. X            return_value0 != (long)SIG_IGN
  1592. X            &&
  1593. X            return_value0 != (long)SIG_HOLD
  1594. X        )
  1595. X            return_value0 = sinfo[signo].sig_handler;
  1596. X
  1597. X        if (return_value0 != (long)SIG_ERR)
  1598. X            sinfo[signo].sig_handler = arg[1];
  1599. X        break;
  1600. X
  1601. X    default:
  1602. X        switch (sigbits)
  1603. X        {
  1604. X        case SIGHOLD:
  1605. X            return_value0 = (long)sighold(signo);
  1606. X            break;
  1607. X
  1608. X        case SIGRELSE:
  1609. X            return_value0 = (long)sigrelse(signo);
  1610. X            break;
  1611. X
  1612. X        case SIGIGNORE:
  1613. X            return_value0 = (long)sigignore(signo);
  1614. X            break;
  1615. X
  1616. X        case SIGPAUSE:
  1617. X            return_value0 = (long)sigpause(signo);
  1618. X            break;
  1619. X
  1620. X        case SIGDEFER:
  1621. X            return_value0 = (long)sigset(signo, our_handler);
  1622. X            if
  1623. X            (
  1624. X                return_value0 != (long)SIG_ERR
  1625. X                &&
  1626. X                return_value0 != (long)SIG_DFL
  1627. X                &&
  1628. X                return_value0 != (long)SIG_IGN
  1629. X                &&
  1630. X                return_value0 != (long)SIG_HOLD
  1631. X            )
  1632. X                return_value0 = sinfo[signo].sig_handler;
  1633. X
  1634. X            if (return_value0 != (long)SIG_ERR)
  1635. X            {
  1636. X                sinfo[signo].sig_handler = arg[1];
  1637. X                sinfo[signo].sig_handler_type = SH_HOLD;
  1638. X                sinfo[signo].sig_tramp = arg[2];
  1639. X            }
  1640. X            break;
  1641. X
  1642. X        default:
  1643. X            return_value0 = (long)sigset(signo, our_handler);
  1644. X            if
  1645. X            (
  1646. X                return_value0 != (long)SIG_ERR
  1647. X                &&
  1648. X                return_value0 != (long)SIG_DFL
  1649. X                &&
  1650. X                return_value0 != (long)SIG_IGN
  1651. X                &&
  1652. X                return_value0 != (long)SIG_HOLD
  1653. X            )
  1654. X                return_value0 = sinfo[signo].sig_handler;
  1655. X
  1656. X            if (return_value0 != (long)SIG_ERR)
  1657. X            {
  1658. X                sinfo[signo].sig_handler = arg[1];
  1659. X                sinfo[signo].sig_handler_type = SH_DFL;
  1660. X                sinfo[signo].sig_tramp = arg[2];
  1661. X            }
  1662. X            break;
  1663. X        }
  1664. X        break;
  1665. X    }
  1666. X
  1667. X    return_errno = errno;
  1668. X
  1669. X    return 0;
  1670. X}
  1671. X
  1672. Xstatic
  1673. Xint
  1674. Xsys_sigreturn(syscallno)
  1675. Xint    syscallno;
  1676. X{
  1677. X    struct sigcontext    sc;
  1678. X    struct sigcontext    *scp;
  1679. X    int            regmask;
  1680. X    int            regi;
  1681. X    int            regbit;
  1682. X
  1683. X    if (mget(arg[0], &sc, sizeof(sc), &scp) == -1)
  1684. X        return -1;
  1685. X
  1686. X    if (scp == (struct sigcontext *)0)
  1687. X    {
  1688. X        return_value0 = -1;
  1689. X        return_errno = EFAULT;
  1690. X        return 0;
  1691. X    }
  1692. X
  1693. X#if    0
  1694. X    /*
  1695. X     * TODO: floating point? exceptions?
  1696. X     */
  1697. X    {
  1698. X        int *srp, *frp;
  1699. X        uint *urp;
  1700. X
  1701. X        scp->sc_ownedfp = u.u_pcb.pcb_ownedfp;
  1702. X
  1703. X        if ((regmask & 1) && u.u_pcb.pcb_ownedfp)
  1704. X        {
  1705. X            checkfp (u.u_procp, 0);    /* dump fp to pcb */
  1706. X            for
  1707. X            (
  1708. X                srp = &scp->sc_fpregs[0], frp = u.u_pcb.pcb_fpregs;
  1709. X                frp < &u.u_pcb.pcb_fpregs[32];
  1710. X                srp++, frp++
  1711. X            )
  1712. X                *srp = *frp;
  1713. X            scp->sc_fpc_csr = u.u_pcb.pcb_fpc_csr;
  1714. X            scp->sc_fpc_eir = u.u_pcb.pcb_fpc_eir;
  1715. X            u.u_pcb.pcb_fpc_csr &= ~FPCSR_EXCEPTIONS;
  1716. X        }
  1717. X
  1718. X        scp->sc_cause = USER_REG(EF_CAUSE);
  1719. X        scp->sc_badvaddr = USER_REG(EF_BADVADDR);
  1720. X    }
  1721. X#endif    /* 0 */
  1722. X
  1723. X    if (quiet_procsput(R_HI, scp->sc_mdhi) == -1)
  1724. X        return -1;
  1725. X
  1726. X    if (quiet_procsput(R_LO, scp->sc_mdlo) == -1)
  1727. X        return -1;
  1728. X
  1729. X    regmask = scp->sc_regmask;
  1730. X
  1731. X    for
  1732. X    (
  1733. X        regi = 1, regbit = 1 << 1;
  1734. X        regi < nels(scp->sc_regs);
  1735. X        regi++, regbit <<= 1
  1736. X    )
  1737. X    {
  1738. X        if (regmask & regbit)
  1739. X        {
  1740. X            int    saved_give_warnings;
  1741. X
  1742. X            if (PG(regi) == R_K0 || PG(regi) == R_K1)
  1743. X            {
  1744. X                saved_give_warnings = give_warnings;
  1745. X                give_warnings = 0;
  1746. X            }
  1747. X
  1748. X            if (quiet_procsput(PG(regi), scp->sc_regs[regi]) == -1)
  1749. X                return -1;
  1750. X
  1751. X            if (PG(regi) == R_K0 || PG(regi) == R_K1)
  1752. X                give_warnings = saved_give_warnings;
  1753. X        }
  1754. X    }
  1755. X
  1756. X    /*
  1757. X     * Set up PC for return.
  1758. X     */
  1759. X    if ((GLOBALdipc = addr_to_decoded_instrnp(GLOBALdipc, scp->sc_pc)) == (dinstrn *)0)
  1760. X        return -1;
  1761. X
  1762. X    GLOBALdipc--;
  1763. X
  1764. X    if (scp->is_sigset != 0)
  1765. X        (void)sigrelse(scp->is_sigset & SIGNO_MASK);
  1766. X
  1767. X    /*
  1768. X     * Set up tidy but unused return values.
  1769. X     */
  1770. X    return_value0 = 0;
  1771. X    return_errno = 0;
  1772. X
  1773. X    return -3;
  1774. X}
  1775. X
  1776. Xstatic
  1777. Xint
  1778. Xsys_stat(syscallno)
  1779. Xint    syscallno;
  1780. X{
  1781. X    struct stat    statb;
  1782. X
  1783. X    return generic_stat(syscallno, &statb, sizeof(statb));
  1784. X}
  1785. X
  1786. Xstatic
  1787. Xint
  1788. Xsys_statfs(syscallno)
  1789. Xint    syscallno;
  1790. X{
  1791. X    char        *cp;
  1792. X    int        len;
  1793. X    struct statfs    buf;
  1794. X    struct statfs    *bufp;
  1795. X
  1796. X    if (mgets(arg[0], &cp) == -1)
  1797. X        return -1;
  1798. X
  1799. X    len = arg[2];
  1800. X
  1801. X    if (mget(arg[1], &buf, len, &bufp) == -1)
  1802. X        return -1;
  1803. X
  1804. X    Rstart;
  1805. X    return_value0 = syscall(syscallno, cp, bufp, len, (int)arg[3]);
  1806. X    return_errno = errno;
  1807. X    Rstop;
  1808. X
  1809. X    if (mput(arg[1], bufp, len, return_value0) == -1)
  1810. X        return -1;
  1811. X
  1812. X    return 0;
  1813. X}
  1814. X
  1815. Xstatic
  1816. Xint
  1817. Xsys_sysfs(syscallno)
  1818. Xint    syscallno;
  1819. X{
  1820. X    char    *cp;
  1821. X    char    buf[FSTYPSZ];
  1822. X
  1823. X    switch (arg[0])
  1824. X    {
  1825. X    case GETFSIND:
  1826. X        if (mgets(arg[1], &cp) == -1)
  1827. X            return -1;
  1828. X
  1829. X        Rstart;
  1830. X        return_value0 = syscall(syscallno, arg[0], cp);
  1831. X        return_errno = errno;
  1832. X        Rstop;
  1833. X
  1834. X        break;
  1835. X
  1836. X    case GETFSTYP:
  1837. X        Rstart;
  1838. X        return_value0 = syscall(syscallno, arg[0], arg[1], &buf[0]);
  1839. X        return_errno = errno;
  1840. X        Rstop;
  1841. X
  1842. X        if (mput(arg[2], &buf[0], sizeof(buf), return_value0) == -1)
  1843. X            return -1;
  1844. X        break;
  1845. X
  1846. X    case GETNFSTYP:
  1847. X        Rstart;
  1848. X        return_value0 = syscall(syscallno, arg[0]);
  1849. X        return_errno = errno;
  1850. X        Rstop;
  1851. X        break;
  1852. X
  1853. X    default:
  1854. X        return -2;
  1855. X    }
  1856. X
  1857. X    return 0;
  1858. X}
  1859. X
  1860. Xstatic
  1861. Xint
  1862. Xsys_times(syscallno)
  1863. Xint    syscallno;
  1864. X{
  1865. X    return generic_times(syscallno, sizeof(struct tms));
  1866. X}
  1867. X
  1868. Xstatic
  1869. Xint
  1870. Xsys_utime(syscallno)
  1871. Xint    syscallno;
  1872. X{
  1873. X    time_t    t[2];
  1874. X
  1875. X    return generic_utime(syscallno, &t[0], sizeof(t));
  1876. X}
  1877. X
  1878. Xstatic
  1879. Xint
  1880. Xsys_utssys(syscallno)
  1881. Xint    syscallno;
  1882. X{
  1883. X    struct utsname    *utsnp;
  1884. X    struct ustat    *ubp;
  1885. X
  1886. X    switch (arg[2])
  1887. X    {
  1888. X    case 0:    /* uname */
  1889. X        if (dmget(arg[0], sizeof(*utsnp), &utsnp) == -1)
  1890. X            return -1;
  1891. X
  1892. X        Rstart;
  1893. X        return_value0 = syscall(syscallno, utsnp, 0, arg[2]);
  1894. X        return_errno = errno;
  1895. X        Rstop;
  1896. X
  1897. X        if (dmput(arg[0], utsnp, sizeof(*utsnp), return_value0) == -1)
  1898. X            return -1;
  1899. X        break;
  1900. X
  1901. X    case 2:    /* ustat */
  1902. X        if (dmget(arg[0], sizeof(*ubp), &ubp) == -1)
  1903. X            return -1;
  1904. X
  1905. X        Rstart;
  1906. X        return_value0 = syscall(syscallno, ubp, arg[1], arg[2]);
  1907. X        return_errno = errno;
  1908. X        Rstop;
  1909. X
  1910. X        if (dmput(arg[0], ubp, sizeof(*ubp), return_value0) == -1)
  1911. X            return -1;
  1912. X        break;
  1913. X
  1914. X    default:
  1915. X        return -2;
  1916. X    }
  1917. X
  1918. X    return 0;
  1919. X}
  1920. X
  1921. Xstatic
  1922. Xint
  1923. Xsys_wait3(syscallno)
  1924. Xint    syscallno;
  1925. X{
  1926. X    union wait    s;
  1927. X    struct rusage    r;
  1928. X
  1929. X    return generic_wait3(syscallno, &s, sizeof(s), &r, sizeof(r));
  1930. X}
  1931. X
  1932. Xstatic sysentry    sysv_systab[]    =
  1933. X{
  1934. X    { "syscall",    1,    "d",    'd',    (int (*)())0,    },
  1935. X    { "_exit",    1,    "d",    'e',    generic_exit,    },
  1936. X    { "fork",    0,    "",    'Y',    generic_fork,    },
  1937. X    { "read",    3,    "dRd",    'd',    generic_read,    },
  1938. X    { "write",    3,    "dWd",    'd',    generic_write,    },
  1939. X    { "open",    3,    "FOm",    'd',    generic_open,    },
  1940. X    { "close",    1,    "d",    'd',    generic_close,    },
  1941. X    { "Owait",    0,    "",    '\0',    (int (*)())0,    },
  1942. X    { "creat",    2,    "Fm",    'd',    generic_creat,    },
  1943. X    { "link",    2,    "FF",    'd',    generic_link,    },
  1944. X
  1945. X    { "unlink",    1,    "F",    'd',    generic_unlink,    },
  1946. X    { "Oexecv",    0,    "",    '\0',    (int (*)())0,    },
  1947. X    { "chdir",    1,    "F",    'd',    generic_chdir,    },
  1948. X    { "time",    1,    "v",    't',    generic_time,    },
  1949. X    { "mknod",    3,    "Fmx",    'd',    generic_mknod,    },
  1950. X    { "chmod",    2,    "Fm",    'd',    generic_chmod,    },
  1951. X    { "chown",    3,    "Fdd",    'd',    generic_chown,    },
  1952. X    { "brk",    1,    "I",    'd',    generic_brk,    },
  1953. X    { "stat",    2,    "FS",    'd',    sys_stat,    },
  1954. X    { "lseek",    3,    "duw",    'u',    generic_lseek,    },
  1955. X
  1956. X    { "getpid",    0,    "",    'd',    generic_getpid,    },
  1957. X    { "mount",    0,    "",    '\0',    (int (*)())0,    },
  1958. X    { "umount",    0,    "",    '\0',    (int (*)())0,    },
  1959. X    { "setuid",    1,    "d",    'd',    generic_setuid,    },
  1960. X    { "getuid",    0,    "",    'Y',    sys_getuid,    },
  1961. X    { "stime",    1,    "v",    'd',    generic_stime,    },
  1962. X    { "ptrace",    4,    "ddxd",    'd',    generic_ptrace,    },
  1963. X    { "alarm",    1,    "d",    'd',    generic_alarm,    },
  1964. X    { "fstat",    2,    "dS",    'd',    sys_fstat,    },
  1965. X    { "pause",    0,    "",    'd',    generic_pause,    },
  1966. X
  1967. X    { "utime",    2,    "FQ",    'd',    sys_utime,    },
  1968. X    { "Ostty",    0,    "",    '\0',    (int (*)())0,    },
  1969. X    { "Ogtty",    0,    "",    '\0',    (int (*)())0,    },
  1970. X    { "access",    2,    "FP",    'd',    generic_access,    },
  1971. X    { "nice",    1,    "d",    'd',    generic_nice,    },
  1972. X    { "statfs",    4,    "FXdd",    'd',    sys_statfs,    },
  1973. X    { "sync",    0,    "",    'd',    generic_sync,    },
  1974. X    { "kill",    2,    "dK",    'd',    generic_kill,    },
  1975. X    { "fstatfs",    4,    "dXdd",    'd',    sys_fstatfs,    },
  1976. X    { "setpgrp",    1,    "d",    'd',    sys_setpgrp,    },
  1977. X
  1978. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  1979. X    { "dup",    1,    "d",    'd',    generic_dup,    },
  1980. X    { "pipe",    0,    "",    'Y',    sys_pipe,    },
  1981. X    { "times",    1,    "k",    'd',    sys_times,    },
  1982. X    { "profil",    4,    "Iddd",    'd',    generic_profil,    },
  1983. X    { "plock",    1,    "d",    'd',    generic_plock,    },
  1984. X    { "setgid",    1,    "d",    'd',    generic_setgid,    },
  1985. X    { "getgid",    0,    "",    'Y',    sys_getgid,    },
  1986. X    { "signal",    3,    "KJI",    'J',    sys_signal,    },
  1987. X    { "msgsys",    0,    "",    '\0',    (int (*)())0,    },
  1988. X
  1989. X    { "sysmips",    0,    "",    '\0',    (int (*)())0,    },
  1990. X    { "acct",    1,    "F",    'd',    generic_acct,    },
  1991. X    { "shmsys",    0,    "",    '\0',    (int (*)())0,    },
  1992. X    { "semsys",    0,    "",    '\0',    (int (*)())0,    },
  1993. X    { "ioctl",    3,    "dCA",    'd',    sys_ioctl,    },
  1994. X    { "uadmin",    3,    "ddd",    'd',    generic_uadmin,    },
  1995. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  1996. X    { "utssys",    3,    "pdd",    'd',    sys_utssys,    },
  1997. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  1998. X    { "execve",    3,    "FlE",    'e',    sys_execve,    },
  1999. X
  2000. X    { "umask",    1,    "x",    'x',    generic_umask,    },
  2001. X    { "chroot",    1,    "F",    'd',    generic_chroot,    },
  2002. X    { "ofcntl",    3,    "dxd",    'd',    sys_ofcntl,    },
  2003. X    { "ulimit",    2,    "dd",    'd',    generic_ulimit,    },
  2004. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2005. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2006. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2007. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2008. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2009. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2010. X
  2011. X    { "advfs",    0,    "",    '\0',    (int (*)())0,    },
  2012. X    { "unadvfs",    0,    "",    '\0',    (int (*)())0,    },
  2013. X    { "rmount",    0,    "",    '\0',    (int (*)())0,    },
  2014. X    { "rumount",    0,    "",    '\0',    (int (*)())0,    },
  2015. X    { "rfstart",    0,    "",    '\0',    (int (*)())0,    },
  2016. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2017. X    { "rdebug",    0,    "",    '\0',    (int (*)())0,    },
  2018. X    { "rfstop",    0,    "",    '\0',    (int (*)())0,    },
  2019. X    { "rfsys",    0,    "",    '\0',    (int (*)())0,    },
  2020. X    { "rmdir",    1,    "F",    'd',    generic_rmdir,    },
  2021. X
  2022. X    { "mkdir",    2,    "Fm",    'd',    generic_mkdir,    },
  2023. X    { "getdents",    3,    "dRd",    'd',    generic_getdents,    },
  2024. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2025. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2026. X    { "sysfs",    3,    "dxp",    'd',    sys_sysfs,    },
  2027. X    { "getmsg",    0,    "",    '\0',    (int (*)())0,    },
  2028. X    { "putmsg",    0,    "",    '\0',    (int (*)())0,    },
  2029. X    { "poll",    3,    "pdd",    'd',    sys_poll,    },
  2030. X    { "sigreturn",    1,    "y",    'd',    sys_sigreturn,    },
  2031. X    { "accept",    3,    "dLU",    'd',    generic_accept,    },
  2032. X
  2033. X    { "bind",    3,    "dLd",    'd',    generic_bind,    },
  2034. X    { "connect",    3,    "dLd",    'd',    generic_connect,    },
  2035. X    { "gethostid",    0,    "",    'u',    generic_gethostid,    },
  2036. X    { "getpeername", 3,    "dLU",    'd',    generic_getpeername, },
  2037. X    { "getsockname", 3,    "dLU",    'd',    generic_getsockname, },
  2038. X    { "getsockopt", 5,    "dddxU", 'd',    generic_getsockopt,    },
  2039. X    { "listen",    2,    "dd",    'd',    generic_listen,    },
  2040. X    { "recv",    4,    "dRdN",    'd',    generic_recv,    },
  2041. X    { "recvfrom",    6,    "dRdNLU", 'd',    sys_recvfrom,    },
  2042. X    { "recvmsg",    3,    "dpN",    'd',    sys_recvmsg,    },
  2043. X
  2044. X    { "select",    5,    "dDDDT", 'd',    sys_select,    },
  2045. X    { "send",    4,    "dWdN",    'd',    generic_send,    },
  2046. X    { "sendmsg",    3,    "dpN",    'd',    sys_sendmsg,    },
  2047. X    { "sendto",    6,    "dWdNLd", 'd',    sys_sendto,    },
  2048. X    { "sethostid",    1,    "u",    'd',    generic_sethostid,    },
  2049. X    { "setsockopt", 5,    "dddpd", 'd',    generic_setsockopt,    },
  2050. X    { "shutdown",    2,    "dd",    'd',    generic_shutdown,    },
  2051. X    { "socket",    3,    "abc",    'd',    generic_socket,    },
  2052. X    { "gethostname", 2,    "xd",    'd',    generic_gethostname, },
  2053. X    { "sethostname", 0,    "",    '\0',    (int (*)())0,    },
  2054. X
  2055. X    { "getdomainname", 2,    "xd",    'd',    generic_getdomainname,    },
  2056. X    { "setdomainname", 2,    "xd",    'd',    generic_setdomainname, },
  2057. X    { "truncate",    2,    "Fu",    'd',    generic_truncate,    },
  2058. X    { "ftruncate",    2,    "du",    'd',    generic_ftruncate,    },
  2059. X    { "rename",    2,    "FF",    'd',    generic_rename,    },
  2060. X    { "symlink",    2,    "FF",    'd',    generic_symlink,    },
  2061. X    { "readlink",    3,    "FRd",    'd',    generic_readlink,    },
  2062. X    { "lstat",    2,    "FS",    'd',    sys_lstat,    },
  2063. X    { "nfsmount",    0,    "",    '\0',    (int (*)())0,    },
  2064. X    { "nfssvc",    0,    "",    'd',    generic_nfssvc,    },
  2065. X
  2066. X    { "getfh",    0,    "",    '\0',    (int (*)())0,    },
  2067. X    { "async_daemon", 0,    "",    'd',    generic_async_daemon, },
  2068. X    { "old_exportfs", 0,    "",    '\0',    (int (*)())0,    },
  2069. X    { "mmap",    0,    "",    '\0',    (int (*)())0,    },
  2070. X    { "munmap",    0,    "",    '\0',    (int (*)())0,    },
  2071. X    { "getitimer",    2,    "dV",    'd',    sys_getitimer,    },
  2072. X    { "setitimer",    3,    "dVV",    'd',    sys_setitimer,    },
  2073. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2074. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2075. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2076. X
  2077. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2078. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2079. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2080. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2081. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2082. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2083. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2084. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2085. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2086. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2087. X
  2088. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2089. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2090. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2091. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2092. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2093. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2094. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2095. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2096. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2097. X    { "",        0,    "",    '\0',    (int (*)())0,    },
  2098. X
  2099. X    { "cacheflush", 3,    "Idd",    'd',    generic_cacheflush,    },
  2100. X    { "cachectl",    3,    "Idd",    'd',    generic_cachectl,    },
  2101. X    { "fchown",    3,    "ddd",    'd',    generic_fchown,    },
  2102. X    { "fchmod",    2,    "dm",    'd',    generic_fchmod,    },
  2103. X    { "wait3",    3,    "hij",    'd',    sys_wait3,    },
  2104. X    { "mmap",    0,    "",    '\0',    (int (*)())0,    },
  2105. X    { "munmap",    0,    "",    '\0',    (int (*)())0,    },
  2106. X    { "madvise",    0,    "",    '\0',    (int (*)())0,    },
  2107. X    { "getpagesize",0,    "",    'd',    generic_getpagesize, },
  2108. X    { "setreuid",    2,    "dd",    'd',    generic_setreuid,    },
  2109. X
  2110. X    { "setregid",    2,    "dd",    'd',    generic_setregid,    },
  2111. X    { "setpgid",    2,    "dd",    'd',    generic_setpgid,    },
  2112. X    { "getgroups",    2,    "dG",    'd',    sys_getgroups,    },
  2113. X    { "setgroups",    2,    "dg",    'd',    generic_setgroups,    },
  2114. X    { "gettimeofday", 2,    "TZ",    'd',    sys_gettimeofday, },
  2115. X    { "getrusage",    2,    "dx",    'd',    sys_getrusage,    },
  2116. X    { "getrlimit",    2,    "dx",    'd',    sys_getrlimit,    },
  2117. X    { "setrlimit",    2,    "dx",    'd',    sys_setrlimit,    },
  2118. X    { "exportfs",    0,    "",    '\0',    (int (*)())0,    },
  2119. X    { "fcntl",    3,    "dBH",    'd',    sys_fcntl,    },
  2120. X#if    0
  2121. XAnd then, a long way on at 260, 261 and 262 there are:
  2122. X    { "netboot",    0,    "",    '\0',    (int (*)())0,    },
  2123. X    { "netunboot",    0,    "",    '\0',    (int (*)())0,    },
  2124. X    { "rdump",    0,    "",    '\0',    (int (*)())0,    },
  2125. Xbut they aren't used.
  2126. X#endif    /* 0 */
  2127. X};
  2128. X
  2129. X#if    defined(LIMITS)
  2130. Xstatic sysentry    limits_sysv_systab[]    =
  2131. X{
  2132. X    { "setlim",    2,    "",    '\0',    (int (*)())0,    }, /* 320 */
  2133. X    { "getlim",    3,    "dxd",    'd',    sys_getlim,    }, /* 321 */
  2134. X    { "limonoff",    1,    "",    '\0',    (int (*)())0,    }, /* 322 */
  2135. X};
  2136. X#endif    /* defined(LIMITS) */
  2137. X
  2138. X#if    defined(SHARE)
  2139. Xstatic sysentry    share_sysv_systab[]    =
  2140. X{
  2141. X    { "sharecosts",    3,    "dxd",    'd',    sys_sharecosts,    }, /* 323 */
  2142. X    { "gettab",    4,    "",    '\0',    (int (*)())0,    }, /* 324 */
  2143. X};
  2144. X#endif    /* defined(SHARE) */
  2145. X
  2146. Xsysentry    *
  2147. Xsysv_systab_entry(n)
  2148. Xint    n;
  2149. X{
  2150. X    int    nn;
  2151. X
  2152. X    if (n >= 0 && n < nels(sysv_systab))
  2153. X        return &sysv_systab[n];
  2154. X
  2155. X#if    defined(LIMITS)
  2156. X    nn = n - (LIMITSoffset - SYSVoffset);
  2157. X
  2158. X    if (nn >= 0 && nn < nels(limits_sysv_systab))
  2159. X        return &limits_sysv_systab[nn];
  2160. X#endif    /* defined(LIMITS) */
  2161. X
  2162. X#if    defined(SHARE)
  2163. X    nn = n - (SHAREoffset - SYSVoffset);
  2164. X
  2165. X    if (nn >= 0 && nn < nels(share_sysv_systab))
  2166. X        return &share_sysv_systab[nn];
  2167. X#endif    /* defined(SHARE) */
  2168. X
  2169. X    return (sysentry *)0;
  2170. X}
  2171. X
  2172. Xint
  2173. Xsysv_print_open_flags(arg)
  2174. Xunsigned long    arg;
  2175. X{
  2176. X    need_leading_pipe = 0;
  2177. X
  2178. X    if ((arg & (O_WRONLY | O_RDWR)) == 0)
  2179. X    {
  2180. X        say_flag(O_RDONLY, "O_RDONLY", arg);
  2181. X    }
  2182. X    else
  2183. X    {
  2184. X        say_flag(O_WRONLY, "O_WRONLY", arg);
  2185. X        say_flag(O_RDWR, "O_RDWR", arg);
  2186. X    }
  2187. X
  2188. X    say_flag(O_APPEND, "O_APPEND", arg);
  2189. X    say_flag(O_CREAT, "O_CREAT", arg);
  2190. X    say_flag(O_EXCL, "O_EXCL", arg);
  2191. X    say_flag(O_NDELAY, "O_NDELAY", arg);
  2192. X    say_flag(O_SYNC, "O_SYNC", arg);
  2193. X    say_flag(O_TRUNC, "O_TRUNC", arg);
  2194. X
  2195. X    say_residual(arg);
  2196. X
  2197. X    return 0;
  2198. X}
  2199. X
  2200. Xint
  2201. Xsysv_print_stat(arg)
  2202. Xlong    arg;
  2203. X{
  2204. X    struct stat    statbuf;
  2205. X
  2206. X    if (quiet_procmget(GLOBALdipc, (unsigned long)arg, (char *)&statbuf, sizeof(statbuf)) == -1)
  2207. X        return -1;
  2208. X
  2209. X    fprintf(outfp, "{" /* } */ );
  2210. X    fprintf(outfp, "st_dev=0x%x,", statbuf.st_dev);
  2211. X    fprintf(outfp, " st_ino=%d,", statbuf.st_ino);
  2212. X    fprintf(outfp, " st_mode=0x%x,", statbuf.st_mode);
  2213. X    fprintf(outfp, " st_nlink=%d,", statbuf.st_nlink);
  2214. X    fprintf(outfp, " st_uid=%d,", statbuf.st_uid);
  2215. X    fprintf(outfp, " st_gid=%d,", statbuf.st_gid);
  2216. X    fprintf(outfp, " st_rdev=0x%x,", statbuf.st_rdev);
  2217. X    fprintf(outfp, " st_size=%d,", statbuf.st_size);
  2218. X    fprintf(outfp, " st_atime=");
  2219. X    say_time(outfp, statbuf.st_atime);
  2220. X    fprintf(outfp, ",");
  2221. X    fprintf(outfp, " st_mtime=");
  2222. X    say_time(outfp, statbuf.st_mtime);
  2223. X    fprintf(outfp, ",");
  2224. X    fprintf(outfp, " st_ctime=");
  2225. X    say_time(outfp, statbuf.st_ctime);
  2226. X    fprintf(outfp, ",");
  2227. X    fprintf(outfp, /* { */ "}");
  2228. X
  2229. X    return 0;
  2230. X}
  2231. X
  2232. Xint
  2233. Xsysv_print_ioctl_cmd(cmd)
  2234. Xunsigned long    cmd;
  2235. X{
  2236. X    char    *cname;
  2237. X
  2238. X    switch (cmd)
  2239. X    {
  2240. X    case FIONREAD:
  2241. X        cname = "FIONREAD";
  2242. X        break;
  2243. X
  2244. X    case I_POP:
  2245. X        cname = "I_POP";
  2246. X        break;
  2247. X
  2248. X    case I_PUSH:
  2249. X        cname = "I_PUSH";
  2250. X        break;
  2251. X
  2252. X    case I_SRDOPT:
  2253. X        cname = "I_SRDOPT";
  2254. X        break;
  2255. X
  2256. X    case STGET:
  2257. X        cname = "STGET";
  2258. X        break;
  2259. X
  2260. X    case oTCGETA:
  2261. X        cname = "oTCGETA";
  2262. X        break;
  2263. X
  2264. X    case TCGETA:
  2265. X        cname = "TCGETA";
  2266. X        break;
  2267. X
  2268. X    case oTCSETA:
  2269. X        cname = "oTCSETA";
  2270. X        break;
  2271. X
  2272. X    case TCSETA:
  2273. X        cname = "TCSETA";
  2274. X        break;
  2275. X
  2276. X    case oTCSETAF:
  2277. X        cname = "oTCSETAF";
  2278. X        break;
  2279. X
  2280. X    case TCSETAF:
  2281. X        cname = "TCSETAF";
  2282. X        break;
  2283. X
  2284. X    case oTCSETAW:
  2285. X        cname = "oTCSETAW";
  2286. X        break;
  2287. X
  2288. X    case TCSETAW:
  2289. X        cname = "TCSETAW";
  2290. X        break;
  2291. X
  2292. X    case TCFLSH:
  2293. X        cname = "TCFLSH";
  2294. X        break;
  2295. X
  2296. X    case TCSBRK:
  2297. X        cname = "TCSBRK";
  2298. X        break;
  2299. X
  2300. X    case TCXONC:
  2301. X        cname = "TCXONC";
  2302. X        break;
  2303. X
  2304. X    case oTIOCEXCL:
  2305. X        cname = "oTIOCEXCL";
  2306. X        break;
  2307. X
  2308. X    case TIOCEXCL:
  2309. X        cname = "TIOCEXCL";
  2310. X        break;
  2311. X
  2312. X    case TIOCGPGRP:
  2313. X        cname = "TIOCGPGRP";
  2314. X        break;
  2315. X
  2316. X    case TIOCGWINSZ:
  2317. X        cname = "TIOCGWINSZ";
  2318. X        break;
  2319. X
  2320. X    case oTIOCHPCL:
  2321. X        cname = "oTIOCHPCL";
  2322. X        break;
  2323. X
  2324. X    case oTIOCNOTTY:
  2325. X        cname = "oTIOCNOTTY";
  2326. X        break;
  2327. X
  2328. X    case TIOCNOTTY:
  2329. X        cname = "TIOCNOTTY";
  2330. X        break;
  2331. X
  2332. X    case oTIOCNXCL:
  2333. X        cname = "oTIOCNXCL";
  2334. X        break;
  2335. X
  2336. X    case TIOCNXCL:
  2337. X        cname = "TIOCNXCL";
  2338. X        break;
  2339. X
  2340. X    case TIOCOUTQ:
  2341. X        cname = "TIOCOUTQ";
  2342. X        break;
  2343. X
  2344. X    case TIOCSPGRP:
  2345. X        cname = "TIOCSPGRP";
  2346. X        break;
  2347. X
  2348. X    case oTIOCSTI:
  2349. X        cname = "oTIOCSTI";
  2350. X        break;
  2351. X
  2352. X    case TIOCSTI:
  2353. X        cname = "TIOCSTI";
  2354. X        break;
  2355. X
  2356. X    case TIOCSWINSZ:
  2357. X        cname = "TIOCSWINSZ";
  2358. X        break;
  2359. X
  2360. X    case LDSETT:
  2361. X        cname = "LDSETT";
  2362. X        break;
  2363. X
  2364. X    default:
  2365. X        cname = (char *)0;
  2366. X        break;
  2367. X    }
  2368. X
  2369. X    if (cname == (char *)0)
  2370. X        fprintf(outfp, "0x%x", cmd);
  2371. X    else
  2372. X        fprintf(outfp, "%s", cname);
  2373. X
  2374. X    return 0;
  2375. X}
  2376. X
  2377. Xstatic
  2378. Xint
  2379. Xsay_termcb(arg)
  2380. Xunsigned long    arg;
  2381. X{
  2382. X    struct termcb    tio;
  2383. X
  2384. X    if (quiet_procmget(GLOBALdipc, arg, &tio, sizeof(tio)) == -1)
  2385. X        return -1;
  2386. X
  2387. X    fprintf(outfp, "{");
  2388. X
  2389. X    /*
  2390. X     * term flags.
  2391. X     */
  2392. X
  2393. X    fprintf(outfp, "st_flgs=");
  2394. X
  2395. X    need_leading_pipe = 0;
  2396. X
  2397. X    say_notflag(TM_NONE, "TM_NONE", tio.st_flgs);
  2398. X    say_flag(TM_SNL, "TM_SNL", tio.st_flgs);
  2399. X    say_flag(TM_ANL, "TM_ANL", tio.st_flgs);
  2400. X    say_flag(TM_LCF, "TM_LCF", tio.st_flgs);
  2401. X    say_flag(TM_CECHO, "TM_CECHO", tio.st_flgs);
  2402. X    say_flag(TM_CINVIS, "TM_CINVIS", tio.st_flgs);
  2403. X    say_flag(TM_SET, "TM_SET", tio.st_flgs);
  2404. X
  2405. X    say_residual(tio.st_flgs);
  2406. X
  2407. X    /*
  2408. X     * term type.
  2409. X     */
  2410. X
  2411. X    fprintf(outfp, ", st_termt=");
  2412. X
  2413. X    switch (tio.st_termt)
  2414. X    {
  2415. X    case TERM_NONE:
  2416. X        fprintf(outfp, "TERM_NONE");
  2417. X        break;
  2418. X
  2419. X    case TERM_TEC:
  2420. X        fprintf(outfp, "TERM_TEC");
  2421. X        break;
  2422. X
  2423. X    case TERM_V61:
  2424. X        fprintf(outfp, "TERM_V61");
  2425. X        break;
  2426. X
  2427. X    case TERM_V10:
  2428. X        fprintf(outfp, "TERM_V10");
  2429. X        break;
  2430. X
  2431. X    case TERM_TEX:
  2432. X        fprintf(outfp, "TERM_TEX");
  2433. X        break;
  2434. X
  2435. X    case TERM_D40:
  2436. X        fprintf(outfp, "TERM_D40");
  2437. X        break;
  2438. X
  2439. X    case TERM_H45:
  2440. X        fprintf(outfp, "TERM_H45");
  2441. X        break;
  2442. X
  2443. X    case TERM_D42:
  2444. X        fprintf(outfp, "TERM_D42");
  2445. X        break;
  2446. X
  2447. X    default:
  2448. X        fprintf(outfp, "0x%x", tio.st_termt);
  2449. X        break;
  2450. X    }
  2451. X
  2452. X    /*
  2453. X     * gtty only - current row.
  2454. X     */
  2455. X    fprintf(outfp, ", st_crow=%d", tio.st_crow);
  2456. X
  2457. X    /*
  2458. X     * gtty only - current col.
  2459. X     */
  2460. X    fprintf(outfp, ", st_ccol=%d", tio.st_ccol);
  2461. X
  2462. X    /*
  2463. X     * variable row.
  2464. X     */
  2465. X    fprintf(outfp, ", st_vrow=%d", tio.st_vrow);
  2466. X
  2467. X    /*
  2468. X     * last row.
  2469. X     */
  2470. X    fprintf(outfp, ", st_lrow=%d", tio.st_lrow);
  2471. X
  2472. X    fprintf(outfp, "}");
  2473. X
  2474. X    return 0;
  2475. X}
  2476. X
  2477. Xstatic
  2478. Xint
  2479. Xsay_termiob(arg)
  2480. Xunsigned long    arg;
  2481. X{
  2482. X    struct termio    tio;
  2483. X
  2484. X    if (quiet_procmget(GLOBALdipc, arg, &tio, sizeof(tio)) == -1)
  2485. X        return -1;
  2486. X
  2487. X    fprintf(outfp, "{");
  2488. X
  2489. X    /*
  2490. X     * Input modes.
  2491. X     */
  2492. X
  2493. X    fprintf(outfp, "c_iflag=");
  2494. X
  2495. X    need_leading_pipe = 0;
  2496. X
  2497. X    say_flag(IGNBRK, "IGNBRK", tio.c_iflag);
  2498. X    say_flag(BRKINT, "BRKINT", tio.c_iflag);
  2499. X    say_flag(IGNPAR, "IGNPAR", tio.c_iflag);
  2500. X    say_flag(PARMRK, "PARMRK", tio.c_iflag);
  2501. X    say_flag(INPCK, "INPCK", tio.c_iflag);
  2502. X    say_flag(ISTRIP, "ISTRIP", tio.c_iflag);
  2503. X    say_flag(INLCR, "INLCR", tio.c_iflag);
  2504. X    say_flag(IGNCR, "IGNCR", tio.c_iflag);
  2505. X    say_flag(ICRNL, "ICRNL", tio.c_iflag);
  2506. X    say_flag(IUCLC, "IUCLC", tio.c_iflag);
  2507. X    say_flag(IXON, "IXON", tio.c_iflag);
  2508. X    say_flag(IXANY, "IXANY", tio.c_iflag);
  2509. X    say_flag(IXOFF, "IXOFF", tio.c_iflag);
  2510. X
  2511. X    say_residual(tio.c_iflag);
  2512. X
  2513. X    /*
  2514. X     * Output modes.
  2515. X     */
  2516. X
  2517. X    fprintf(outfp, ", c_oflag=");
  2518. X
  2519. X    need_leading_pipe = 0;
  2520. X
  2521. X    say_flag(OPOST, "OPOST", tio.c_oflag);
  2522. X    say_flag(OLCUC, "OLCUC", tio.c_oflag);
  2523. X    say_flag(ONLCR, "ONLCR", tio.c_oflag);
  2524. X    say_flag(OCRNL, "OCRNL", tio.c_oflag);
  2525. X    say_flag(ONOCR, "ONOCR", tio.c_oflag);
  2526. X    say_flag(ONLRET, "ONLRET", tio.c_oflag);
  2527. X    say_flag(OFILL, "OFILL", tio.c_oflag);
  2528. X    say_flag(OFDEL, "OFDEL", tio.c_oflag);
  2529. X
  2530. X    say_notflag(NLDLY, "NL0", tio.c_oflag);
  2531. X    say_flag(NL1, "NL1", tio.c_oflag);
  2532. X
  2533. X    say_notflag(CRDLY, "CR0", tio.c_oflag);
  2534. X    say_flag(CR3, "CR3", tio.c_oflag);
  2535. X    say_flag(CR2, "CR2", tio.c_oflag);
  2536. X    say_flag(CR1, "CR1", tio.c_oflag);
  2537. X
  2538. X    say_notflag(TABDLY, "TAB0", tio.c_oflag);
  2539. X    say_flag(TAB3, "TAB3", tio.c_oflag);
  2540. X    say_flag(TAB2, "TAB2", tio.c_oflag);
  2541. X    say_flag(TAB1, "TAB1", tio.c_oflag);
  2542. X
  2543. X    say_notflag(BSDLY, "BS0", tio.c_oflag);
  2544. X    say_flag(BS1, "BS1", tio.c_oflag);
  2545. X
  2546. X    say_notflag(VTDLY, "VT0", tio.c_oflag);
  2547. X    say_flag(VT1, "VT1", tio.c_oflag);
  2548. X
  2549. X    say_notflag(FFDLY, "FF0", tio.c_oflag);
  2550. X    say_flag(FF1, "FF1", tio.c_oflag);
  2551. X
  2552. X    say_residual(tio.c_oflag);
  2553. X
  2554. X    /*
  2555. X     * Hardware control modes.
  2556. X     */
  2557. X
  2558. X    fprintf(outfp, ", c_cflag=");
  2559. X
  2560. X    switch (tio.c_cflag & CBAUD)
  2561. X    {
  2562. X    case B0:
  2563. X        fprintf(outfp, "B0");
  2564. X        break;
  2565. X
  2566. X    case B50:
  2567. X        fprintf(outfp, "B50");
  2568. X        break;
  2569. X
  2570. X    case B75:
  2571. X        fprintf(outfp, "B75");
  2572. X        break;
  2573. X
  2574. X    case B110:
  2575. X        fprintf(outfp, "B110");
  2576. X        break;
  2577. X
  2578. X    case B134:
  2579. X        fprintf(outfp, "B134");
  2580. X        break;
  2581. X
  2582. X    case B150:
  2583. X        fprintf(outfp, "B150");
  2584. X        break;
  2585. X
  2586. X    case B200:
  2587. X        fprintf(outfp, "B200");
  2588. X        break;
  2589. X
  2590. X    case B300:
  2591. X        fprintf(outfp, "B300");
  2592. X        break;
  2593. X
  2594. X    case B600:
  2595. X        fprintf(outfp, "B600");
  2596. X        break;
  2597. X
  2598. X    case B1200:
  2599. X        fprintf(outfp, "B1200");
  2600. X        break;
  2601. X
  2602. X    case B1800:
  2603. X        fprintf(outfp, "B1800");
  2604. X        break;
  2605. X
  2606. X    case B2400:
  2607. X        fprintf(outfp, "B2400");
  2608. X        break;
  2609. X
  2610. X    case B4800:
  2611. X        fprintf(outfp, "B4800");
  2612. X        break;
  2613. X
  2614. X    case B9600:
  2615. X        fprintf(outfp, "B9600");
  2616. X        break;
  2617. X
  2618. X    case B19200:
  2619. X        fprintf(outfp, "B19200");
  2620. X        break;
  2621. X
  2622. X    case B38400:
  2623. X        fprintf(outfp, "B38400");
  2624. X        break;
  2625. X    }
  2626. X
  2627. X    tio.c_cflag &= ~CBAUD;
  2628. X
  2629. X    need_leading_pipe = 1;
  2630. X
  2631. X    say_notflag(CSIZE, "CS5", tio.c_cflag);
  2632. X    say_flag(CS8, "CS8", tio.c_cflag);
  2633. X    say_flag(CS7, "CS7", tio.c_cflag);
  2634. X    say_flag(CS6, "CS6", tio.c_cflag);
  2635. X
  2636. X    say_flag(CSTOPB, "CSTOPB", tio.c_cflag);
  2637. X    say_flag(CREAD, "CREAD", tio.c_cflag);
  2638. X    say_flag(PARENB, "PARENB", tio.c_cflag);
  2639. X    say_flag(PARODD, "PARODD", tio.c_cflag);
  2640. X    say_flag(HUPCL, "HUPCL", tio.c_cflag);
  2641. X    say_flag(CLOCAL, "CLOCAL", tio.c_cflag);
  2642. X    say_flag(CNEW_RTSCTS, "CNEW_RTSCTS", tio.c_cflag);
  2643. X    say_flag(LOBLK, "LOBLK", tio.c_cflag);
  2644. X    say_flag(CNEW_MDMBUF, "CNEW_MDMBUF", tio.c_cflag);
  2645. X
  2646. X    say_residual(tio.c_cflag);
  2647. X
  2648. X    /*
  2649. X     * Local flags.
  2650. X     */
  2651. X
  2652. X    fprintf(outfp, ", c_lflag=");
  2653. X
  2654. X    need_leading_pipe = 0;
  2655. X
  2656. X    say_flag(ISIG, "ISIG", tio.c_lflag);
  2657. X    say_flag(ICANON, "ICANON", tio.c_lflag);
  2658. X    say_flag(XCASE, "XCASE", tio.c_lflag);
  2659. X    say_flag(ECHO, "ECHO", tio.c_lflag);
  2660. X    say_flag(ECHOE, "ECHOE", tio.c_lflag);
  2661. X    say_flag(ECHOK, "ECHOK", tio.c_lflag);
  2662. X    say_flag(ECHONL, "ECHONL", tio.c_lflag);
  2663. X    say_flag(NOFLSH, "NOFLSH", tio.c_lflag);
  2664. X    say_flag(TOSTOP, "TOSTOP", tio.c_lflag);
  2665. X    say_flag(LNEW_CTLECH, "LNEW_CTLECH", tio.c_lflag);
  2666. X    say_flag(LNEW_PRTERA, "LNEW_PRTERA", tio.c_lflag);
  2667. X    say_flag(LNEW_CRTBS, "LNEW_CRTBS", tio.c_lflag);
  2668. X    say_flag(LNEW_PENDIN, "LNEW_PENDIN", tio.c_lflag);
  2669. X    say_flag(LNEW_FLUSHO, "LNEW_FLUSHO", tio.c_lflag);
  2670. X
  2671. X    say_residual(tio.c_lflag);
  2672. X
  2673. X    /*
  2674. X     * Line discipline.
  2675. X     */
  2676. X
  2677. X    fprintf(outfp, ", c_line=%d", tio.c_line);
  2678. X
  2679. X    /*
  2680. X     * Control chars.
  2681. X     */
  2682. X
  2683. X    fprintf(outfp, ", c_cc=[");
  2684. X    fprintf(outfp, "VINTR=0x%02x,", tio.c_cc[VINTR]);
  2685. X    fprintf(outfp, "VQUIT=0x%02x,", tio.c_cc[VQUIT]);
  2686. X    fprintf(outfp, "VERASE=0x%02x,", tio.c_cc[VERASE]);
  2687. X    fprintf(outfp, "VKILL=0x%02x,", tio.c_cc[VKILL]);
  2688. X    fprintf(outfp, "VEOF=0x%02x,", tio.c_cc[VEOF]);
  2689. X    fprintf(outfp, "VEOL=0x%02x,", tio.c_cc[VEOL]);
  2690. X    fprintf(outfp, "VEOL2=0x%02x,", tio.c_cc[VEOL2]);
  2691. X    fprintf(outfp, "VSWTCH=0x%02x,", tio.c_cc[VSWTCH]);
  2692. X    fprintf(outfp, "V_START=0x%02x,", tio.c_cc[V_START]);
  2693. X    fprintf(outfp, "V_STOP=0x%02x,", tio.c_cc[V_STOP]);
  2694. X    fprintf(outfp, "V_SUSP=0x%02x,", tio.c_cc[V_SUSP]);
  2695. X    fprintf(outfp, "V_DSUSP=0x%02x,", tio.c_cc[V_DSUSP]);
  2696. X    fprintf(outfp, "V_RPRNT=0x%02x,", tio.c_cc[V_RPRNT]);
  2697. X    fprintf(outfp, "V_FLUSH=0x%02x,", tio.c_cc[V_FLUSH]);
  2698. X    fprintf(outfp, "V_WERAS=0x%02x,", tio.c_cc[V_WERAS]);
  2699. X    fprintf(outfp, "V_LNEXT=0x%02x,", tio.c_cc[V_LNEXT]);
  2700. X    fprintf(outfp, "V_STATUS=0x%02x,", tio.c_cc[V_STATUS]);
  2701. X    fprintf(outfp, "V_SAVED_EOF=0x%02x,", tio.c_cc[V_SAVED_EOF]);
  2702. X    fprintf(outfp, "V_SAVED_EOL=0x%02x,", tio.c_cc[V_SAVED_EOL]);
  2703. X    fprintf(outfp, "19=0x%02x,", tio.c_cc[19]);
  2704. X    fprintf(outfp, "20=0x%02x,", tio.c_cc[20]);
  2705. X    fprintf(outfp, "21=0x%02x,", tio.c_cc[21]);
  2706. X    fprintf(outfp, "22=0x%02x,", tio.c_cc[22]);
  2707. X    fprintf(outfp, "]");
  2708. X
  2709. X    /*
  2710. X     * (bsd43) saved flags.
  2711. X     */
  2712. X
  2713. X    fprintf(outfp, ", c_saved_flags=0x%x", tio.c_saved_flags);
  2714. X
  2715. X    /*
  2716. X     * Filler.
  2717. X     */
  2718. X
  2719. X    fprintf(outfp, ", c_filler=0x%x", tio.c_filler);
  2720. X
  2721. X    fprintf(outfp, "}");
  2722. X
  2723. X    return 0;
  2724. X}
  2725. X
  2726. Xint
  2727. Xsysv_print_ioctl_arg(args)
  2728. Xunsigned long    *args;
  2729. X{
  2730. X    int    i;
  2731. X
  2732. X    switch (args[1])
  2733. X    {
  2734. X    case FIONREAD:
  2735. X        if (quiet_procmget(GLOBALdipc, (unsigned long)args[2], &i, sizeof(i)) == -1)
  2736. X            return -1;
  2737. X
  2738. X        fprintf(outfp, "{*(int *)0x%x=%d}", args[2], i);
  2739. X        break;
  2740. X
  2741. X    case TCGETA:
  2742. X    case TCSETA:
  2743. X    case TCSETAW:
  2744. X    case TCSETAF:
  2745. X        if (say_termiob(args[2]) == -1)
  2746. X            return -1;
  2747. X
  2748. X        break;
  2749. X
  2750. X    case LDSETT:
  2751. X        if (say_termcb(args[2]) == -1)
  2752. X            return -1;
  2753. X
  2754. X        break;
  2755. X
  2756. X    default:
  2757. X        fprintf(outfp, "0x%x", args[2]);
  2758. X        break;
  2759. X    }
  2760. X
  2761. X    return 0;
  2762. X}
  2763. X
  2764. Xint
  2765. Xsysv_print_fdset(nfds, arg)
  2766. Xint        nfds;
  2767. Xunsigned long    arg;
  2768. X{
  2769. X    if (arg == (unsigned long)0)
  2770. X        fprintf(outfp, "0x%x", arg);
  2771. X    else
  2772. X    {
  2773. X        struct fd_set    tfds;
  2774. X        int        fd;
  2775. X
  2776. X        if (quiet_procmget(GLOBALdipc, arg, &tfds, sizeof(tfds)) == -1)
  2777. X            return -1;
  2778. X
  2779. X        fprintf(outfp, "{");
  2780. X
  2781. X        for (fd = 0; fd < nfds; fd++)
  2782. X        {
  2783. X            if (FD_ISSET(fd, &tfds))
  2784. X                fprintf(outfp, "%d,", fd);
  2785. X        }
  2786. X
  2787. X        fprintf(outfp, "}");
  2788. X    }
  2789. X
  2790. X    return 0;
  2791. X}
  2792. X
  2793. Xint
  2794. Xsysv_print_whence(arg)
  2795. Xunsigned long    arg;
  2796. X{
  2797. X    switch (arg)
  2798. X    {
  2799. X    case SEEK_SET:
  2800. X        fprintf(outfp, "SEEK_SET");
  2801. X        break;
  2802. X
  2803. X    case SEEK_CUR:
  2804. X        fprintf(outfp, "SEEK_CUR");
  2805. X        break;
  2806. X
  2807. X    case SEEK_END:
  2808. X        fprintf(outfp, "SEEK_END");
  2809. X        break;
  2810. X
  2811. X    default:
  2812. X        fprintf(outfp, "0x%x", arg);
  2813. X        break;
  2814. X    }
  2815. X
  2816. X    return 0;
  2817. X}
  2818. X
  2819. Xint
  2820. Xsysv_print_statfs(arg)
  2821. Xunsigned long    arg;
  2822. X{
  2823. X    if (arg == (unsigned long)0)
  2824. X        fprintf(outfp, "0x%x", arg);
  2825. X    else
  2826. X    {
  2827. X        struct statfs    t;
  2828. X
  2829. X        if (quiet_procmget(GLOBALdipc, arg, &t, sizeof(t)) == -1)
  2830. X            return -1;
  2831. X
  2832. X        fprintf(outfp, "{");
  2833. X        fprintf(outfp, "fstyp=%d,", t.f_fstyp);
  2834. X        fprintf(outfp, "bsize=%d,", t.f_bsize);
  2835. X        fprintf(outfp, "frsize=%d,", t.f_frsize);
  2836. X        fprintf(outfp, "blocks=%d,", t.f_blocks);
  2837. X        fprintf(outfp, "bfree=%d,", t.f_bfree);
  2838. X        fprintf(outfp, "files=%d,", t.f_files);
  2839. X        fprintf(outfp, "ffree=%d,", t.f_ffree);
  2840. X        vis_quoted_truncated_buffer(outfp, sizeof(t.f_fname), &t.f_fname[0], sizeof(t.f_fname));
  2841. X        fprintf(outfp, ",");
  2842. X        vis_quoted_truncated_buffer(outfp, sizeof(t.f_fpack), &t.f_fpack[0], sizeof(t.f_fpack));
  2843. X        fprintf(outfp, "}");
  2844. X    }
  2845. X    return 0;
  2846. X}
  2847. X
  2848. Xint
  2849. Xsysv_print_wait3_union_wait(arg)
  2850. Xunsigned long    arg;
  2851. X{
  2852. X    union wait    w;
  2853. X    union wait    *wp;
  2854. X
  2855. X    if (mget(arg, &w, sizeof(w), &wp) == -1)
  2856. X        return -1;
  2857. X
  2858. X    if (wp == (union wait *)0)
  2859. X        fprintf(outfp, "0x%x", arg);
  2860. X    else
  2861. X    {
  2862. X        fprintf(outfp, "{" /* } */);
  2863. X
  2864. X        if (w.w_status == WSTOPPED)
  2865. X        {
  2866. X            fprintf(outfp, "w_stopval=WSTOPPED,");
  2867. X            fprintf(outfp, "w_stopsig=%s", signal_name(w.w_stopsig));
  2868. X        }
  2869. X        else
  2870. X        {
  2871. X            fprintf(outfp, "w_termsig=%s,", signal_name(w.w_termsig));
  2872. X            fprintf(outfp, "w_coredump=%d,", w.w_coredump);
  2873. X            fprintf(outfp, "w_retcode=%d", w.w_retcode);
  2874. X        }
  2875. X
  2876. X        fprintf(outfp, /* { */ "}");
  2877. X    }
  2878. X
  2879. X    return 0;
  2880. X}
  2881. X
  2882. Xint
  2883. Xsysv_print_wait3_options(arg)
  2884. Xunsigned long    arg;
  2885. X{
  2886. X    if (arg == (unsigned long)0)
  2887. X        fprintf(outfp, "0x%x", arg);
  2888. X    else
  2889. X    {
  2890. X        need_leading_pipe = 0;
  2891. X
  2892. X        say_flag(WNOHANG, "WNOHANG", arg);
  2893. X        say_flag(WUNTRACED, "WUNTRACED", arg);
  2894. X
  2895. X        say_residual(arg);
  2896. X    }
  2897. X
  2898. X    return 0;
  2899. X}
  2900. X
  2901. Xint
  2902. Xsysv_print_wait3_rusage(arg)
  2903. Xunsigned long    arg;
  2904. X{
  2905. X    fprintf(outfp, "0x%x", arg);
  2906. X
  2907. X    return 0;
  2908. X}
  2909. X
  2910. Xint
  2911. Xsysv_print_sigcontext(outfp, p)
  2912. XFILE        *outfp;
  2913. Xunsigned long    p;
  2914. X{
  2915. X    struct sigcontext    sc;
  2916. X    struct sigcontext    *scp;
  2917. X    int            i;
  2918. X
  2919. X    fprintf(outfp, "{" /* } */);
  2920. X
  2921. X    if (mget(p, &sc, sizeof(sc), &scp) == -1)
  2922. X        return -1;
  2923. X
  2924. X    if (Aflag)
  2925. X    {
  2926. X        if (scp != (struct sigcontext *)0)
  2927. X        {
  2928. X            fprintf(outfp, "regmask=0x%x,", scp->sc_regmask);
  2929. X            fprintf(outfp, "mask=0x%x,", scp->sc_mask);
  2930. X            fprintf(outfp, "pc=%s,", proc_text_address(scp->sc_pc));
  2931. X
  2932. X            for (i = 0; i < nels(scp->sc_regs); i++)
  2933. X                fprintf(outfp, "regs[%d]=0x%x,", i, scp->sc_regs[i]);
  2934. X
  2935. X            fprintf(outfp, "ownedfp=0x%x,", scp->sc_ownedfp);
  2936. X
  2937. X            for (i = 0; i < nels(scp->sc_fpregs); i++)
  2938. X                fprintf(outfp, "fpregs[%d]=0x%x,", i, scp->sc_fpregs[i]);
  2939. X
  2940. X            fprintf(outfp, "fpc_csr=0x%x,", scp->sc_fpc_csr);
  2941. X            fprintf(outfp, "fpc_eir=0x%x,", scp->sc_fpc_eir);
  2942. X            fprintf(outfp, "mdhi=%d,", scp->sc_mdhi);
  2943. X            fprintf(outfp, "mdlo=%d,", scp->sc_mdlo);
  2944. X            fprintf(outfp, "cause=0x%x,", scp->sc_cause);
  2945. X            fprintf(outfp, "badvaddr=0x%x,", scp->sc_badvaddr);
  2946. X            fprintf(outfp, "badpaddr=0x%x,", scp->sc_badpaddr);
  2947. X            fprintf(outfp, "sigset=%s,", signal_name(scp->is_sigset));
  2948. X        }
  2949. X    }
  2950. X    else
  2951. X        fprintf(outfp, "...");
  2952. X
  2953. X    fprintf(outfp, /* { */ "}");
  2954. X
  2955. X    return 0;
  2956. X}
  2957. X
  2958. Xstatic
  2959. Xint
  2960. Xsysv_print_received_signal(universe, universe_name, tramp, handler, sig, code, scp)
  2961. Xint            universe;
  2962. Xchar            *universe_name;
  2963. Xunsigned long        tramp;
  2964. Xunsigned long        handler;
  2965. Xint            sig;
  2966. Xint            code;
  2967. Xstruct sigcontext    *scp;
  2968. X{
  2969. X    fprintf(outfp, "%6d:", P.p_pid);
  2970. X
  2971. X    fprintf(outfp, "%s_SIGNAL(", universe_name);
  2972. X
  2973. X    if (printval(universe, tramp, 'I', (unsigned long *)0, (unsigned long)0, (unsigned long)0, DIRN_ENTRY) == -1)
  2974. X        return -1;
  2975. X
  2976. X    fprintf(outfp, ", ");
  2977. X
  2978. X    if (printval(universe, handler, 'I', (unsigned long *)0, (unsigned long)0, (unsigned long)0, DIRN_ENTRY) == -1)
  2979. X        return -1;
  2980. X
  2981. X    fprintf(outfp, ", ");
  2982. X
  2983. X    if (printval(universe, sig, 'K', (unsigned long *)0, (unsigned long)0, (unsigned long)0, DIRN_ENTRY) == -1)
  2984. X        return -1;
  2985. X
  2986. X    fprintf(outfp, ", ");
  2987. X
  2988. X    if (printval(universe, code, 'd', (unsigned long *)0, (unsigned long)0, (unsigned long)0, DIRN_ENTRY) == -1)
  2989. X        return -1;
  2990. X
  2991. X    fprintf(outfp, ", ");
  2992. X
  2993. X    if (printval(universe, scp, 'y', (unsigned long *)0, (unsigned long)0, (unsigned long)0, DIRN_ENTRY) == -1)
  2994. X        return -1;
  2995. X
  2996. X    fprintf(outfp, ")");
  2997. X
  2998. X    fprintf(outfp, "\n");
  2999. X
  3000. X    return 0;
  3001. X}
  3002. END_OF_FILE
  3003. if test 58975 -ne `wc -c <'sysv.c'`; then
  3004.     echo shar: \"'sysv.c'\" unpacked with wrong size!
  3005. fi
  3006. # end of 'sysv.c'
  3007. fi
  3008. echo shar: End of archive 8 \(of 8\).
  3009. cp /dev/null ark8isdone
  3010. MISSING=""
  3011. for I in 1 2 3 4 5 6 7 8 ; do
  3012.     if test ! -f ark${I}isdone ; then
  3013.     MISSING="${MISSING} ${I}"
  3014.     fi
  3015. done
  3016. if test "${MISSING}" = "" ; then
  3017.     echo You have unpacked all 8 archives.
  3018.     rm -f ark[1-9]isdone
  3019. else
  3020.     echo You still need to unpack the following archives:
  3021.     echo "        " ${MISSING}
  3022. fi
  3023. ##  End of shell archive.
  3024. exit 0
  3025.